Class: RegexForms::ValidatePassword

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(password) ⇒ ValidatePassword

Returns a new instance of ValidatePassword.



74
75
76
# File 'lib/regex_forms.rb', line 74

def initialize(password)
  @password = password
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



72
73
74
# File 'lib/regex_forms.rb', line 72

def password
  @password
end

Instance Method Details

#validatePasswordObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/regex_forms.rb', line 78

def validatePassword
  return invalid_response("Password is nil, empty, or all zeros") if invalid_password

  regex = /\A.*(?=.*\d)(?=.*[!@#$%^&*]).*\z/

  if regex.match(password)
    valid_response("Validated Password")
  else
    invalid_response("Must contain at least one digit and one special character: #{password}")
  end
end