-
Notifications
You must be signed in to change notification settings - Fork 203
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
299b2fc
commit 373eca7
Showing
3 changed files
with
72 additions
and
3 deletions.
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,5 +1,6 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <cctype> | ||
#include "validation.hpp" | ||
|
||
int main() { | ||
|
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,53 @@ | ||
#include "validation.hpp" | ||
// TODO: Put implementations here | ||
#include <algorithm> | ||
#include <cctype> | ||
|
||
std::string getErrorMessage(ErrorCode error) { | ||
switch (error) { | ||
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"; | ||
} | ||
return "Undefined error"; | ||
} | ||
|
||
bool doPasswordsMatch(std::string password1, std::string password2) { | ||
return password1 == password2; | ||
} | ||
|
||
ErrorCode checkPasswordRules(std::string password) { | ||
if (password.length() < 9) { | ||
return ErrorCode::PasswordNeedsAtLeastNineCharacters; | ||
} | ||
if (!std::any_of(password.begin(), password.end(), [](unsigned char c) { return std::isdigit(c); })) { | ||
return ErrorCode::PasswordNeedsAtLeastOneNumber; | ||
} | ||
if (!std::any_of(password.begin(), password.end(), [](unsigned char c) { return std::ispunct(c); })) { | ||
return ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter; | ||
} | ||
if (!std::any_of(password.begin(), password.end(), [](unsigned char c) { return std::isupper(c); })) { | ||
return ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter; | ||
} | ||
return ErrorCode::Ok; | ||
} | ||
|
||
ErrorCode checkPassword(std::string password1, std::string password2) { | ||
if (doPasswordsMatch(password1, password2)) { | ||
return checkPasswordRules(password1); | ||
} | ||
return ErrorCode::PasswordsDoNotMatch; | ||
} |
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,19 @@ | ||
// TODO: I'm empty :) Put enum and function headers here. | ||
// Don't forget the header guard - #pragma once | ||
#pragma once | ||
#include <string> | ||
|
||
enum class ErrorCode { | ||
Ok, | ||
PasswordNeedsAtLeastNineCharacters, | ||
PasswordNeedsAtLeastOneNumber, | ||
PasswordNeedsAtLeastOneSpecialCharacter, | ||
PasswordNeedsAtLeastOneUppercaseLetter, | ||
PasswordsDoNotMatch | ||
}; | ||
|
||
std::string getErrorMessage(ErrorCode error); | ||
|
||
bool doPasswordsMatch(std::string password1, std::string password2); | ||
|
||
ErrorCode checkPasswordRules(std::string password); | ||
|
||
ErrorCode checkPassword(std::string password1, std::string password2); |