Class: Sequel::Plugins::Password::SHA1Hasher
- Defined in:
- lib/sequel_password.rb
Instance Attribute Summary
Attributes inherited from Hasher
Instance Method Summary collapse
- #encode(password, salt) ⇒ Object
-
#initialize ⇒ SHA1Hasher
constructor
A new instance of SHA1Hasher.
- #verify(password, encoded) ⇒ Object
Methods inherited from Hasher
Constructor Details
#initialize ⇒ SHA1Hasher
Returns a new instance of SHA1Hasher.
168 169 170 171 |
# File 'lib/sequel_password.rb', line 168 def initialize @algorithm = :sha1 @digest = OpenSSL::Digest::SHA1.new end |
Instance Method Details
#encode(password, salt) ⇒ Object
173 174 175 176 |
# File 'lib/sequel_password.rb', line 173 def encode(password, salt) hash = @digest.digest(salt + password).unpack('H*').first "#{@algorithm}$#{salt}$#{hash}" end |
#verify(password, encoded) ⇒ Object
178 179 180 181 182 |
# File 'lib/sequel_password.rb', line 178 def verify(password, encoded) algorithm, salt, hash = encoded.split('$', 3) hash = encode(password, salt) constant_time_compare(encoded, hash) end |