Class: MiscHacks::Password
- Inherits:
-
Object
- Object
- MiscHacks::Password
- Defined in:
- lib/mischacks/password.rb
Constant Summary collapse
- SALT_SET =
'a'..'z', 'A'..'Z', '0'..'9', %w{ . / }].map(&:to_a).flatten
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #=~(password) ⇒ Object
-
#initialize(encrypted) ⇒ Password
constructor
A new instance of Password.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(encrypted) ⇒ Password
Returns a new instance of Password.
35 36 37 38 39 40 |
# File 'lib/mischacks/password.rb', line 35 def initialize encrypted @salt, @encrypted = encrypted.scan(/\A(\$[^$]+\$[^$]+\$)(.+)\z/).first if @salt.nil? or @encrypted.nil? raise ArgumentError, "Failed to parse #{encrypted.inspect}", caller end end |
Class Method Details
.new_from_password(password) ⇒ Object
31 32 33 |
# File 'lib/mischacks/password.rb', line 31 def self.new_from_password password new password.crypt('$6$%s$' % random_salt) end |
Instance Method Details
#==(other) ⇒ Object
46 47 48 |
# File 'lib/mischacks/password.rb', line 46 def == other to_s == other.to_s end |
#=~(password) ⇒ Object
42 43 44 |
# File 'lib/mischacks/password.rb', line 42 def =~ password to_s == password.crypt(@salt) end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/mischacks/password.rb', line 54 def inspect '#<%s: %s>' % [self.class, to_s.inspect] end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/mischacks/password.rb', line 50 def to_s [@salt, @encrypted].join end |