module ActiveModel::SecurePassword::InstanceMethodsOnActivation
def authenticate(unencrypted_password)
user.authenticate('notright') # => false
user.save
user = User.new(name: 'david', password: 'mUc3m00RsqyRe')
end
has_secure_password validations: false
class User < ActiveRecord::Base
Returns +self+ if the password is correct, otherwise +false+.
def authenticate(unencrypted_password) BCrypt::Password.new(password_digest).is_password?(unencrypted_password) && self end
def password=(unencrypted_password)
user.password = 'mUc3m00RsqyRe'
user.password_digest # => nil
user.password = nil
user = User.new
end
has_secure_password validations: false
class User < ActiveRecord::Base
new password is not empty.
Encrypts the password into the +password_digest+ attribute, only if the
def password=(unencrypted_password) if unencrypted_password.nil? self.password_digest = nil elsif !unencrypted_password.empty? @password = unencrypted_password cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost self.password_digest = BCrypt::Password.create(unencrypted_password, cost: cost) end end
def password_confirmation=(unencrypted_password)
def password_confirmation=(unencrypted_password) @password_confirmation = unencrypted_password end