Class: Pwl::ReasonableComplexityPasswordPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/pwl/password_policy.rb

Instance Method Summary collapse

Instance Method Details

#validate!(pwd) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/pwl/password_policy.rb', line 21

def validate!(pwd)
  raise InvalidMasterPasswordError.new("May not be blank") if pwd.blank?
  raise InvalidMasterPasswordError.new("Must have at least eight characters") if 8 > pwd.length
  raise InvalidMasterPasswordError.new("Must contain at least one integer") unless pwd =~ /.*\d/
  raise InvalidMasterPasswordError.new("Must contain at least one character (lower or upper case)") unless pwd =~ /.*([a-z]|[A-Z])/
  raise InvalidMasterPasswordError.new("Special characters are only allowed if their ASCII value is between 0x20 and 0x7E") unless pwd =~ /[\x20-\x7E]/
end