Class: ActiveModel::Validations::ZxcvbnPasswordValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/tough/validators/zxcvbn_password_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/tough/validators/zxcvbn_password_validator.rb', line 4

def validate_each(record, attribute, value)
  #0 too guessable: risky password. (guesses < 10^3)
  #1 very guessable: protection from throttled online attacks. (guesses < 10^6)
  #2 somewhat guessable: protection from unthrottled online attacks. (guesses < 10^8)
  #3 safely unguessable: moderate protection from offline slow-hash scenario. (guesses < 10^10)
  #4 very unguessable: strong protection from offline slow-hash scenario. (guesses >= 10^10)
  unless Zxcvbn.test(value).score >= Tough.zxcvbn_minimum_score_to_pass
    record.errors[attribute] << Tough.zxcvbn_error_message 
  end
end