diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index ba912c87..8a78db83 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -3,29 +3,29 @@ #include #include #include - -enum class Error { +enum class ErrorCode { Ok, PasswordNeedsAtLeastNineCharacters, PasswordNeedsAtLeastOneNumber, PasswordNeedsAtLeastOneSpecialCharacter, PasswordNeedsAtLeastOneUppercaseLetter, PasswordsDoNotMatch - }; +}; + std::string getErrorMessage(int errcode) { switch (errcode) { - case 0: - return "Ok"; - case 1: - return "Password Needs AtLeast Nine Characters"; - case 2: - return "Password Needs AtLeast OneNumber"; - case 3: - return "Password Needs AtLeast One Special Character"; - case 4: - return "Password Needs AtLeast One Uppercase Letter"; - case 5: - return "Passwords Do Not Match"; + case 0: + return "Ok"; + case 1: + return "Password Needs AtLeast Nine Characters"; + case 2: + return "Password Needs AtLeast OneNumber"; + case 3: + return "Password Needs AtLeast One Special Character"; + case 4: + return "Password Needs AtLeast One Uppercase Letter"; + case 5: + return "Passwords Do Not Match"; } } @@ -34,17 +34,17 @@ bool doPasswordsMatch(std::string psw1, std::string psw2) { return true; else return false; - } +} int checkPasswordRules(std::string pass) { int i; - Error back; + ErrorCode back; bool OneNumber, OneUppercaseLetter, OneSpecialCharacter; OneNumber = false; OneUppercaseLetter = false; OneSpecialCharacter = false; if (pass.length()<9) - return static_cast (back = Error::PasswordNeedsAtLeastNineCharacters); + return static_cast (back = ErrorCode::PasswordNeedsAtLeastNineCharacters); for (auto element : pass) { if (isdigit(element)) OneNumber = true; @@ -52,20 +52,21 @@ int checkPasswordRules(std::string pass) { OneSpecialCharacter = true; if (isupper(element)) OneUppercaseLetter = true; - } + } if (!OneNumber) - return static_cast (back = Error::PasswordNeedsAtLeastOneNumber); + return static_cast(back = ErrorCode::PasswordNeedsAtLeastOneNumber); else if (!OneUppercaseLetter) - return static_cast (back = Error::PasswordNeedsAtLeastOneUppercaseLetter); + return static_cast(back = ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter); else if (!OneSpecialCharacter) - return static_cast (back = Error::PasswordNeedsAtLeastOneSpecialCharacter); - else return static_cast (back = Error::Ok); + return static_cast (back = ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter); + else return static_cast (back = ErrorCode::Ok); } + int checkPassword(std::string firstpassword, std::string secondpassword) { if (!doPasswordsMatch(firstpassword, secondpassword)) - return static_cast(Error::PasswordsDoNotMatch); + return static_cast(ErrorCode::PasswordsDoNotMatch); else return checkPasswordRules(firstpassword); }