Class: DeviseMeteor::BCryptSHA256Hasher
- Defined in:
- lib/devise_meteor/strategies/hasher.rb
Overview
BCryptSHA256Hasher implements a BCrypt password hasher using SHA256.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Hasher
Instance Method Summary collapse
- #encode(password, salt) ⇒ Object
- #get_password_string(password) ⇒ 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.
53 54 55 56 57 |
# File 'lib/devise_meteor/strategies/hasher.rb', line 53 def initialize @algorithm = :bcrypt_sha256 @cost = 10 @digest = OpenSSL::Digest::SHA256.new end |
Instance Method Details
#encode(password, salt) ⇒ Object
67 68 69 70 71 |
# File 'lib/devise_meteor/strategies/hasher.rb', line 67 def encode(password, salt) password = get_password_string(password) hash = BCrypt::Engine.hash_secret(password, salt) return hash end |
#get_password_string(password) ⇒ Object
63 64 65 |
# File 'lib/devise_meteor/strategies/hasher.rb', line 63 def get_password_string(password) @digest.digest(password) unless @digest.nil? end |
#salt ⇒ Object
59 60 61 |
# File 'lib/devise_meteor/strategies/hasher.rb', line 59 def salt BCrypt::Engine.generate_salt(@cost) end |
#verify(password, encoded) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/devise_meteor/strategies/hasher.rb', line 73 def verify(password, encoded) password_digest = get_password_string(password) hash = BCrypt::Engine.hash_secret(password_digest, encoded) Devise.secure_compare(encoded, hash) constant_time_compare(encoded, hash) end |