Module: Models::PasswordAuthentication

Defined in:
lib/_models/password_authentication.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SITE_KEY =

TODO1 remove this key

'3eed5a60c1bf8d43de5d0560e9fc2442fe74fdad'
DIGEST_STRETCHES =
10
PASSWORD_LENGTH =
3..40

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#crypted_passwordObject

Returns the value of attribute crypted_password.



7
8
9
# File 'lib/_models/password_authentication.rb', line 7

def crypted_password
  @crypted_password
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/_models/password_authentication.rb', line 9

def password
  @password
end

#saltObject

Returns the value of attribute salt.



7
8
9
# File 'lib/_models/password_authentication.rb', line 7

def salt
  @salt
end

Instance Method Details

#authenticated_by_password?(password) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/_models/password_authentication.rb', line 20

def authenticated_by_password? password
  return false if crypted_password.blank? or password.blank?
  self.crypted_password == self.class.encrypt_password(password, salt)
end

#update_password(password, password_confirmation, old_password) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/_models/password_authentication.rb', line 25

def update_password password, password_confirmation, old_password
  if crypted_password.blank?
    self.password, self.password_confirmation = password, password_confirmation
  elsif authenticated_by_password? old_password
    self.password, self.password_confirmation = password, password_confirmation
    true
  else
    errors.add :base, t(:invalid_old_password)
    false
  end
end