Module: ActiveModel::SecurePassword::InstanceMethodsOnActivation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password


98
99
100
# File 'activemodel/lib/active_model/secure_password.rb', line 98

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

94
95
96
# File 'activemodel/lib/active_model/secure_password.rb', line 94

def authenticate(unencrypted_password)
  BCrypt::Password.new(password_digest).is_password?(unencrypted_password) && self
end

#password_confirmation=(unencrypted_password) ⇒ Object


122
123
124
# File 'activemodel/lib/active_model/secure_password.rb', line 122

def password_confirmation=(unencrypted_password)
  @password_confirmation = unencrypted_password
end