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)


30
31
32
33
# File 'lib/devise/secure_password/models/password_disallows_frequent_changes.rb', line 30

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

#validate_password_frequent_changeObject



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

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: precise_distance_of_time_in_words(self.class.password_minimum_age)
    )
    errors.add(:base, error_string)
  end

  errors.count.zero?
end