Methods
Class Public methods
new() Link
# File activemodel/lib/active_model/secure_password/bcrypt_password.rb, line 11 def initialize # Load bcrypt gem only when has_secure_password is used. # This is to avoid Active Model (and by extension the entire framework) # being dependent on a binary library. require "bcrypt" rescue LoadError warn "You don't have bcrypt installed in your application. Please add it to your Gemfile and run bundle install." raise end
Instance Public methods
algorithm_name() Link
Returns the algorithm name.
hash_password(unencrypted_password) Link
Hashes the unencrypted password using BCrypt.
password_salt(digest) Link
Generates the salt from the password digest.
validate(record, attribute) Link
Validates the password and adds error to the record in the given attribute. BCrypt has a maximum input size, so we need to validate it.
# File activemodel/lib/active_model/secure_password/bcrypt_password.rb, line 38 def validate(record, attribute) password = record.public_send(attribute) if password.present? record.errors.add(attribute, :password_too_long) if password.bytesize > MAX_PASSWORD_LENGTH_ALLOWED end end