Class: ActiveModel::Validations::PasswordStrengthValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::PasswordStrengthValidator
- Defined in:
- lib/active_model/validations/password_strength_validator.rb
Instance Method Summary collapse
- #extra_words_for_object(extra_words, object) ⇒ Object
- #strength_options(options, object) ⇒ Object
- #validate_each(object, attribute, value) ⇒ Object
Instance Method Details
#extra_words_for_object(extra_words, object) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_model/validations/password_strength_validator.rb', line 19 def extra_words_for_object(extra_words, object) return [] unless extra_words.present? if object if extra_words.respond_to?(:call) extra_words = extra_words.call(object) elsif extra_words.kind_of? Symbol extra_words = object.send(extra_words) end end extra_words || [] end |
#strength_options(options, object) ⇒ Object
13 14 15 16 17 |
# File 'lib/active_model/validations/password_strength_validator.rb', line 13 def (, object) = .dup [:extra_dictionary_words] = extra_words_for_object([:extra_dictionary_words], object) .slice(:min_entropy, :use_dictionary, :min_word_length, :extra_dictionary_words) end |
#validate_each(object, attribute, value) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/active_model/validations/password_strength_validator.rb', line 6 def validate_each(object, attribute, value) ps = ::StrongPassword::StrengthChecker.new(**(, object)) unless ps.is_strong?(value.to_s) object.errors.add(attribute, :'password.password_strength', .merge(:value => value.to_s)) end end |