Class: UserPassword

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user_password.rb

Constant Summary collapse

MAX_PASSWORD_LENGTH =
200
TARGET_PASSWORD_ALGORITHM =
"$pbkdf2-#{Rails.configuration.pbkdf2_algorithm}$i=#{Rails.configuration.pbkdf2_iterations},l=32$"
PASSWORD_SALT_LENGTH =
16

Instance Method Summary collapse

Instance Method Details

#confirm_password?(pw) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
# File 'app/models/user_password.rb', line 32

def confirm_password?(pw)
  # nothing to confirm if this record has not been persisted yet
  return false if !persisted?
  return false if password_hash != hash_password(pw, password_salt, password_algorithm)
  regen_password!(pw) if password_algorithm != TARGET_PASSWORD_ALGORITHM

  true
end

#passwordObject



16
17
18
19
# File 'app/models/user_password.rb', line 16

def password
  # this getter method is still required, but we store the set password in @raw_password instead of making it easily accessible from the getter
  nil
end

#password=(pw) ⇒ Object



21
22
23
24
25
26
# File 'app/models/user_password.rb', line 21

def password=(pw)
  return if pw.blank?

  self.password_hash_will_change!
  @raw_password = pw
end

#password_validation_required?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/user_password.rb', line 28

def password_validation_required?
  @raw_password.present?
end