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 between 8 and 20 characters with no spaces', :regex => '^\S{8,20}$'}
  record.errors[attribute] << password_validation_hash[:error_message] unless Regexp.new(password_validation_hash[:regex]) =~ value
end