Class: Devise::Hashable::Strategy::Bcrypt
- Defined in:
- lib/devise/hashable/strategy/bcrypt.rb
Overview
Wrapper for the Devise' standard encryption strategy Bcrypt
Class Method Summary collapse
-
.compare(klass, encrypted_password, password) ⇒ Boolean
Verifies a plain-text password against a bcrypt hash.
-
.digest(klass, password) ⇒ String
Hashes a plain-text password with bcrypt.
- .password_configurations_match?(klass, encrypted_password) ⇒ Boolean
- .split_password_hash(encrypted_password) ⇒ Object
Class Method Details
.compare(klass, encrypted_password, password) ⇒ Boolean
Verifies a plain-text password against a bcrypt hash.
15 16 17 |
# File 'lib/devise/hashable/strategy/bcrypt.rb', line 15 def compare(klass, encrypted_password, password) Devise::Encryptor.compare(klass, encrypted_password, password) end |
.digest(klass, password) ⇒ String
Hashes a plain-text password with bcrypt.
24 25 26 |
# File 'lib/devise/hashable/strategy/bcrypt.rb', line 24 def digest(klass, password) Devise::Encryptor.digest(klass, password) end |
.password_configurations_match?(klass, encrypted_password) ⇒ Boolean
28 29 30 31 32 33 34 35 |
# File 'lib/devise/hashable/strategy/bcrypt.rb', line 28 def password_configurations_match?(klass, encrypted_password) current_password_configs = split_password_hash(encrypted_password) required_password_configs = base_configs(klass) return false if current_password_configs[:stretches] != [required_password_configs[:stretches], 4].max true end |
.split_password_hash(encrypted_password) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/devise/hashable/strategy/bcrypt.rb', line 37 def split_password_hash(encrypted_password) split_digest = encrypted_password.split("$") raise InvalidPasswordHash, "Invalid password hash for Bcrypt" unless split_digest.length == 4 _, strategy, stretches, _checksum = split_digest raise InvalidPasswordHash, "Invalid password hash strategy for Bcrypt" unless strategy == "2a" { stretches: stretches.to_i } end |