Class: Sequel::Plugins::Password::BCryptSHA256Hasher
- Defined in:
- lib/sequel_password.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Hasher
Instance Method Summary collapse
- #encode(password, salt) ⇒ Object
-
#initialize ⇒ BCryptSHA256Hasher
constructor
A new instance of BCryptSHA256Hasher.
- #salt ⇒ Object
- #verify(password, encoded) ⇒ Object
Methods inherited from Hasher
Constructor Details
#initialize ⇒ BCryptSHA256Hasher
Returns a new instance of BCryptSHA256Hasher.
135 136 137 138 139 |
# File 'lib/sequel_password.rb', line 135 def initialize @algorithm = :bcrypt_sha256 @cost = 12 @digest = OpenSSL::Digest::SHA256.new end |
Instance Method Details
#encode(password, salt) ⇒ Object
145 146 147 148 149 |
# File 'lib/sequel_password.rb', line 145 def encode(password, salt) password = @digest.digest(password) unless @digest.nil? hash = BCrypt::Engine.hash_secret(password, salt) "#{@algorithm}$#{hash}" end |
#salt ⇒ Object
141 142 143 |
# File 'lib/sequel_password.rb', line 141 def salt BCrypt::Engine.generate_salt(@cost) end |
#verify(password, encoded) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/sequel_password.rb', line 151 def verify(password, encoded) algorithm, data = encoded.split('$', 2) password = @digest.digest(password) unless @digest.nil? hash = BCrypt::Engine.hash_secret(password, data) constant_time_compare(data, hash) end |