Module: ActiveModel::SecurePassword::InstanceMethodsOnActivation

Defined in:
activemodel/lib/active_model/secure_password.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(unencrypted_password) ⇒ Object

Returns self if the password is correct, otherwise false.



57
58
59
60
61
62
63
# File 'activemodel/lib/active_model/secure_password.rb', line 57

def authenticate(unencrypted_password)
  if BCrypt::Password.new(password_digest) == unencrypted_password
    self
  else
    false
  end
end

#password=(unencrypted_password) ⇒ Object

Encrypts the password into the password_digest attribute.



66
67
68
69
70
71
# File 'activemodel/lib/active_model/secure_password.rb', line 66

def password=(unencrypted_password)
  @password = unencrypted_password
  unless unencrypted_password.blank?
    self.password_digest = BCrypt::Password.create(unencrypted_password)
  end
end