Module: ActiveModel::SecurePassword::InstanceMethodsOnActivation
- Defined in:
- lib/active_model/secure_password.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
-
#authenticate(unencrypted_password) ⇒ Object
Returns
self
if the password is correct, otherwisefalse
. - #password_confirmation=(unencrypted_password) ⇒ Object
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
100 101 102 |
# File 'lib/active_model/secure_password.rb', line 100 def password @password end |
Instance Method Details
#authenticate(unencrypted_password) ⇒ Object
Returns self
if the password is correct, otherwise false
.
class User < ActiveRecord::Base
has_secure_password validations: false
end
user = User.new(name: 'david', password: 'mUc3m00RsqyRe')
user.save
user.authenticate('notright') # => false
user.authenticate('mUc3m00RsqyRe') # => user
96 97 98 |
# File 'lib/active_model/secure_password.rb', line 96 def authenticate(unencrypted_password) BCrypt::Password.new(password_digest).is_password?(unencrypted_password) && self end |
#password_confirmation=(unencrypted_password) ⇒ Object
124 125 126 |
# File 'lib/active_model/secure_password.rb', line 124 def password_confirmation=(unencrypted_password) @password_confirmation = unencrypted_password end |