-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8786eea
commit d6b696b
Showing
1 changed file
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,56 @@ | ||
#include "validation.hpp" | ||
// TODO: Put implementations here | ||
std::string getErrorMessage(ErrorCode error) { | ||
switch (error) { | ||
default: | ||
return ""; | ||
|
||
case ErrorCode::Ok: | ||
return "Ok"; | ||
|
||
case ErrorCode::PasswordNeedsAtLeastNineCharacters: | ||
return "PasswordNeedsAtLeastNineCharacters"; | ||
|
||
case ErrorCode::PasswordNeedsAtLeastOneNumber: | ||
return "PasswordNeedsAtLeastOneNumber"; | ||
|
||
case ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter: | ||
return "PasswordNeedsAtLeastOneSpecialCharacter"; | ||
|
||
case ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter: | ||
return "PasswordNeedsAtLeastOneUppercaseLetter"; | ||
|
||
case ErrorCode::PasswordsDoNotMatch: | ||
return "PasswordsDoNotMatch"; | ||
} | ||
} | ||
|
||
bool doPasswordsMatch(const std::string &password1, const std::string &password2) { | ||
if (password1 == password2) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
ErrorCode checkPasswordRules(const std::string &password) { | ||
// first i will try to check if theres at least 9 characters | ||
if (password.length() < 9) { | ||
return ErrorCode::PasswordNeedsAtLeastNineCharacters; | ||
} | ||
// if predycate if there is none of the numbers rerturn errorcode | ||
else if (std::none_of(password.begin(), password.end(), [](char c) { return std::isdigit(c); })) { | ||
return ErrorCode::PasswordNeedsAtLeastOneNumber; | ||
} else if (std::none_of(password.begin(), password.end(), [](char c) { return std::isupper(c); })) { | ||
return ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter; | ||
} else if (std::none_of(password.begin(), password.end(), [](char c) { return std::ispunct(c); })) { | ||
return ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter; | ||
} else | ||
return ErrorCode::Ok; | ||
} | ||
|
||
ErrorCode checkPassword(const std::string &password1, const std::string &password2) { | ||
if (doPasswordsMatch(password1, password2)) | ||
return checkPasswordRules(password1); | ||
else | ||
return ErrorCode::PasswordsDoNotMatch; | ||
} |