Class: Sequel::Plugins::Password::SHA1Hasher

Inherits:
Hasher
  • Object
show all
Defined in:
lib/sequel_password.rb

Instance Attribute Summary

Attributes inherited from Hasher

#algorithm

Instance Method Summary collapse

Methods inherited from Hasher

#must_update, #salt

Constructor Details

#initializeSHA1Hasher

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