Skip to content

Commit

Permalink
done but still doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
MiKaz003 committed Aug 30, 2024
1 parent ca87e11 commit 6ae9f1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
42 changes: 18 additions & 24 deletions homework/password-check/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
#include <vector>
// TODO: Put implementations here

enum class ErrorCode{
Ok,
PasswordNeedsAtLeastNineCharacters,
PasswordNeedsAtLeastOneNumber,
PasswordNeedsAtLeastOneSpecialCharacter,
PasswordNeedsAtLeastOneUppercaseLetter,
PasswordsDoNotMatch
};
bool doPasswordsMatch(std::string& pass1, std::string& pass2) {
if (pass1 == pass2) {
return true;
Expand Down Expand Up @@ -39,7 +31,7 @@ ErrorCode checkPasswordRules(std::string pass) {
}
}

ErrorCode checkPassword(std::string pass, std::string repPass){
ErrorCode checkPassword(std::string& pass, std::string& repPass){
if (doPasswordsMatch(pass, repPass)){
return checkPasswordRules(pass);
}
Expand All @@ -48,19 +40,21 @@ ErrorCode checkPassword(std::string pass, std::string repPass){
}
}

std::string getErrorMessage(int errorNum){
static const std::vector<std::string> errorMessages = {
"Ok",
"Password needs to have at least nine characters",
"Password needs to have at least one number",
"Password needs to have at least one special character",
"Password needs to have at least one uppercase letter",
"Passwords do not match",
};
if (errorNum >= 0 && errorNum <= static_cast<int>(errorMessages.size())){
return errorMessages[errorNum];
std::string getErrorMessage(ErrorCode& errorNum){
switch(errorNum){
case ErrorCode::Ok:
return "Ok";
case ErrorCode::PasswordNeedsAtLeastNineCharacters:
return "Password needs to have at least nine characters";
case ErrorCode::PasswordNeedsAtLeastOneNumber:
return "Password needs to have at least one number";
case ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter:
return "Password needs to have at least one special character";
case ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter:
return "Password needs to have at least one uppercase letter";
case ErrorCode::PasswordsDoNotMatch:
return "Passwords do not match";
default:
return "Unknown error";
}
else{
return "Unknown error";
}
}
}
4 changes: 2 additions & 2 deletions homework/password-check/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ enum class ErrorCode{
PasswordNeedsAtLeastOneUppercaseLetter,
PasswordsDoNotMatch
};
std::string getErrorMessage(int errorNum);
std::string getErrorMessage(ErrorCode& errorNum);
bool doPasswordsMatch(std::string& pass1, std::string& pass2);
ErrorCode checkPasswordRules(std::string pass);
ErrorCode checkPassword(std::string pass, std::string repPass);
ErrorCode checkPassword(std::string& pass, std::string& repPass);
bool checkSpecialChar(std::string& pass);

0 comments on commit 6ae9f1c

Please sign in to comment.