Class: PasswordStrengthValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/password_strength_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

implement the method where the validation logic must reside



3
4
5
6
# File 'app/validators/password_strength_validator.rb', line 3

def validate_each(record, attribute, value)
  password_validation_hash = record.password_validator || {:error_message => 'must be at least 8 characters long and start and end with a letter', :regex => '^[A-Za-z]\w{6,}[A-Za-z]$'}
  record.errors[attribute] << password_validation_hash[:error_message] unless Regexp.new(password_validation_hash[:regex]) =~ value
end