class Sequel::Plugins::Password::Hasher
@!attribute [r] algorithm
@return [Symbol] name of the alogorithm implemented by the hasher
@abstract Subclass or override this class to implements a custom
Hasher.
Attributes
algorithm[R]
Public Instance Methods
encode(_password, _salt)
click to toggle source
Returns given password encoded with the given salt.
@param [String] password in plain text @param [String] salt to be used during hashing @return [String] given password hashed using the given salt
# File lib/sequel_password/hashers.rb, line 39 def encode(_password, _salt) raise NotImplementedError end
must_update(_encoded)
click to toggle source
Returns if given encoded password needs to be updated.
@param [String] encoded password @return [Boolean] if encoded password needs to be updated
# File lib/sequel_password/hashers.rb, line 47 def must_update(_encoded) false end
salt()
click to toggle source
Returns salt value to be used for hashing.
@return [String] random salt value.
# File lib/sequel_password/hashers.rb, line 20 def salt # 72 bits SecureRandom.hex(9) end
verify(_password, _encoded)
click to toggle source
Returns if the given password match the encoded password.
@param [String] password in plain text @param [String] encoded password to be matched @return [Boolean] if password match encoded password.
# File lib/sequel_password/hashers.rb, line 30 def verify(_password, _encoded) raise NotImplementedError end
Private Instance Methods
constant_time_compare(a, b)
click to toggle source
# File lib/sequel_password/hashers.rb, line 53 def constant_time_compare(a, b) check = a.bytesize ^ b.bytesize a.bytes.zip(b.bytes) { |x, y| check |= x ^ y } check.zero? end