Module: Devise::Models::PasswordDisallowsFrequentChanges

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/secure_password/models/password_disallows_frequent_changes.rb

Defined Under Namespace

Modules: ClassMethods Classes: ConfigurationError

Instance Method Summary collapse

Instance Method Details

#password_recent?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/devise/secure_password/models/password_disallows_frequent_changes.rb', line 28

def password_recent?
  last_password = previous_passwords.unscoped.last
  last_password&.fresh?(self.class.password_minimum_age)
end

#validate_password_frequent_changeObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/devise/secure_password/models/password_disallows_frequent_changes.rb', line 16

def validate_password_frequent_change
  if encrypted_password_changed? && password_recent?
    error_string = I18n.t(
      'secure_password.password_disallows_frequent_changes.errors.messages.password_is_recent',
      timeframe: distance_of_time_in_words(self.class.password_minimum_age)
    )
    errors.add(:base, error_string)
  end

  errors.count.zero?
end