Class: ActiveModel::SecurePassword::Argon2Password
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | activemodel/lib/active_model/secure_password/argon2_password.rb |
Class Method Summary
- .new ⇒ Argon2Password constructor
Instance Method Summary
-
#algorithm_name
Returns the algorithm name.
-
#hash_password(unencrypted_password)
Hashes the unencrypted password using Argon2.
-
#password_salt(digest)
Generates the salt from the password digest.
-
#validate(_record, _attribute)
Validates the password and adds error to the record in the given attribute.
-
#verify_password(password, digest)
Verifies if the password matches the digest.
Constructor Details
.new ⇒ Argon2Password
# File 'activemodel/lib/active_model/secure_password/argon2_password.rb', line 6
def initialize # Load argon2 gem only when has_secure_password with :argon2 is used. # This is to avoid Active Model (and by extension the entire framework) # being dependent on a binary library. require "argon2" rescue LoadError warn "You don't have argon2 installed in your application. Please add it to your Gemfile and run bundle install." raise end
Instance Method Details
#algorithm_name
Returns the algorithm name.
# File 'activemodel/lib/active_model/secure_password/argon2_password.rb', line 41
def algorithm_name :argon2 end
#hash_password(unencrypted_password)
Hashes the unencrypted password using Argon2.
# File 'activemodel/lib/active_model/secure_password/argon2_password.rb', line 17
def hash_password(unencrypted_password) if ActiveModel::SecurePassword.min_cost ::Argon2::Password.new(profile: :unsafe_cheapest).create(unencrypted_password) else ::Argon2::Password.create(unencrypted_password) end end
#password_salt(digest)
Generates the salt from the password digest.
# File 'activemodel/lib/active_model/secure_password/argon2_password.rb', line 31
def password_salt(digest) ::Argon2::HashFormat.new(digest).salt end
#validate(_record, _attribute)
Validates the password and adds error to the record in the given attribute. Argon2 has no maximum input size, no validation needed.
# File 'activemodel/lib/active_model/secure_password/argon2_password.rb', line 37
def validate(_record, _attribute) end
#verify_password(password, digest)
Verifies if the password matches the digest.
# File 'activemodel/lib/active_model/secure_password/argon2_password.rb', line 26
def verify_password(password, digest) ::Argon2::Password.verify_password(password, digest) end