Module: Devise::Models::PasswordArchivable::InstanceMethods

Defined in:
lib/devise_security_extension/models/password_archivable.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#password_archive_included?Boolean

validate is the password used in the past

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/devise_security_extension/models/password_archivable.rb', line 25

def password_archive_included?
  unless self.class.deny_old_passwords.is_a? Fixnum
    if self.class.deny_old_passwords.is_a? TrueClass and self.class.password_archiving_count > 0
      self.class.deny_old_passwords = self.class.password_archiving_count
    else
      self.class.deny_old_passwords = 0
    end
  end

  if self.class.deny_old_passwords > 0 and not self.password.nil?
    self.old_passwords.order('created_at DESC').limit(self.class.deny_old_passwords).limit(self.class.deny_old_passwords).each do |old_password|
      dummy                    = self.class.new
      dummy.encrypted_password = old_password.encrypted_password
      dummy.password_salt      = old_password.password_salt
      return true if dummy.valid_password?(self.password)
    end
  end

  false
end

#validate_password_archiveObject



20
21
22
# File 'lib/devise_security_extension/models/password_archivable.rb', line 20

def validate_password_archive
  self.errors.add(:password, :taken_in_past) if password_archive_included?
end