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


105
106
107
# File 'activemodel/lib/active_model/secure_password.rb', line 105

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

101
102
103
# File 'activemodel/lib/active_model/secure_password.rb', line 101

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

#password_confirmation=(unencrypted_password) ⇒ Object


129
130
131
# File 'activemodel/lib/active_model/secure_password.rb', line 129

def password_confirmation=(unencrypted_password)
  @password_confirmation = unencrypted_password
end