Skip to content

Commit

Permalink
almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
MiKaz003 committed Aug 30, 2024
1 parent 6cf3023 commit ca87e11
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 8 additions & 8 deletions homework/password-check/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ bool checkSpecialChar(std::string& pass) {
return pass.find_first_of(special_chars) != std::string::npos;
}

int checkPasswordRules(std::string& pass) {
ErrorCode checkPasswordRules(std::string pass) {
if (std::none_of(pass.begin(), pass.end(), ::isupper)) {
return (static_cast<int>(ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter));
return ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter;
} else if (std::none_of(pass.begin(), pass.end(), ::isdigit)) {
return (static_cast<int>(ErrorCode::PasswordNeedsAtLeastOneNumber));
return ErrorCode::PasswordNeedsAtLeastOneNumber;
} else if (!checkSpecialChar(pass)) {
return (static_cast<int>(ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter));
return ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter;
} else if (pass.length() < 9) {
return (static_cast<int>(ErrorCode::PasswordNeedsAtLeastNineCharacters));
return ErrorCode::PasswordNeedsAtLeastNineCharacters;
} else {
return (static_cast<int>(ErrorCode::Ok));
return ErrorCode::Ok;
}
}

int checkPassword(std::string& pass, std::string& repPass){
ErrorCode checkPassword(std::string pass, std::string repPass){
if (doPasswordsMatch(pass, repPass)){
return checkPasswordRules(pass);
}
else{
return (static_cast<int> (ErrorCode::PasswordsDoNotMatch));
return ErrorCode::PasswordsDoNotMatch;
}
}

Expand Down
13 changes: 10 additions & 3 deletions homework/password-check/validation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
// TODO: I'm empty :) Put enum and function headers here.
// Don't forget the header guard - #pragma once

enum class ErrorCode;
enum class ErrorCode{
Ok,
PasswordNeedsAtLeastNineCharacters,
PasswordNeedsAtLeastOneNumber,
PasswordNeedsAtLeastOneSpecialCharacter,
PasswordNeedsAtLeastOneUppercaseLetter,
PasswordsDoNotMatch
};
std::string getErrorMessage(int errorNum);
bool doPasswordsMatch(std::string& pass1, std::string& pass2);
int checkPasswordRules(std::string& pass);
int checkPassword(std::string& pass, std::string repPass);
ErrorCode checkPasswordRules(std::string pass);
ErrorCode checkPassword(std::string pass, std::string repPass);
bool checkSpecialChar(std::string& pass);

0 comments on commit ca87e11

Please sign in to comment.