upper_and_lower_case_characters.rb 575 B

1234567891011121314151617181920
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class PasswordPolicy
  3. class UpperAndLowerCaseCharacters < PasswordPolicy::Backend
  4. UPPER_LOWER_REGEXPS = [%r{\p{Upper}.*\p{Upper}}, %r{\p{Lower}.*\p{Lower}}].freeze
  5. def valid?
  6. UPPER_LOWER_REGEXPS.all? { |regexp| @password.match?(regexp) }
  7. end
  8. def error
  9. [__('Invalid password, it must contain at least 2 lowercase and 2 uppercase characters!')]
  10. end
  11. def self.applicable?
  12. Setting.get('password_min_2_lower_2_upper_characters').to_i == 1
  13. end
  14. end
  15. end