Skip to content

Commit

Permalink
Update validation.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
VeniGogniti authored Jul 7, 2024
1 parent d34cd76 commit 89a5375
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions homework/password-check/validation.cpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
#include "validation.hpp"

std::string getErrorMessage(ErrorCode code) {
switch (code) {
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 "Error";
}
}

bool doPasswordsMatch(std::string pwd1, std::string pwd2) {
if (pwd1 == pwd2) {
return true;
}
return false;
}

ErrorCode checkPasswordRules(std::string pwd) {
std::string charToChekc = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890!@#$%^&*()";
if (pwd.size() >= 9) {
for (int it = 0; it <= pwd.size(); it++) {
if (!isupper(pwd[it])) {
return ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter;
}
if (!ispunct(pwd[it])) {
return ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter;
}
if (!isdigit(pwd[it])) {
return ErrorCode::PasswordNeedsAtLeastOneNumber;
}
}
return ErrorCode::Ok;

} else if (pwd.size() < 9) {
return ErrorCode::PasswordNeedsAtLeastNineCharacters;
}
return ErrorCode::Ok;
}

ErrorCode checkPassword(std::string password, std::string repPassword) {
if (!doPasswordsMatch(password, repPassword)) {
return ErrorCode::PasswordsDoNotMatch;
}
return checkPasswordRules(password);
}
#include "validation.hpp"
ErrorCode checkPassword(std::string password, std::string repPassword) {
if (!doPasswordsMatch(password, repPassword)) {
return ErrorCode::PasswordsDoNotMatch;
}
return checkPasswordRules(password);
}

0 comments on commit 89a5375

Please sign in to comment.