From 55ba6428fb0d3bf08b660b175d9285f42d234936 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 13:46:30 +0000 Subject: [PATCH 01/11] Add enum class ErrorCode --- homework/password-check/validation.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index 85160868..320e1d12 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -1,2 +1,13 @@ // TODO: I'm empty :) Put enum and function headers here. -// Don't forget the header guard - #pragma once \ No newline at end of file +// Don't forget the header guard - #pragma once + +#pragma once + +enum class ErrorCode { + Ok, + PasswordNeedsAtLeastNineCharacters, + PasswordNeedsAtLeastOneNumber, + PasswordNeedsAtLeastOneSpecialCharacter, + PasswordNeedsAtLeastOneUppercaseLetter, + PasswordsDoNotMatch +}; \ No newline at end of file From bb7862a540a2e73bf8c7b58d0ab9009d4b547208 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 14:27:32 +0000 Subject: [PATCH 02/11] Add getErrorMessage function --- homework/password-check/main.cpp | 1 + homework/password-check/validation.cpp | 31 +++++++++++++++++++++++++- homework/password-check/validation.hpp | 5 ++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/homework/password-check/main.cpp b/homework/password-check/main.cpp index 254ccc11..1c735999 100644 --- a/homework/password-check/main.cpp +++ b/homework/password-check/main.cpp @@ -1,3 +1,4 @@ +#pragma once #include #include #include "validation.hpp" diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index a2f12ff3..5ee6cde2 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,2 +1,31 @@ +#pragma once +#include #include "validation.hpp" -// TODO: Put implementations here \ No newline at end of file +// TODO: Put implementations here + +std::string getErrorMessage(ErrorCode errorCode) { + std::string errorMessage{}; + switch(errorCode) { + case ErrorCode::Ok: + errorMessage = "Ok"; + break; + case ErrorCode::PasswordNeedsAtLeastNineCharacters: + errorMessage = "Password needs to have at least nine characters"; + break; + case ErrorCode::PasswordNeedsAtLeastOneNumber: + errorMessage = "Password needs to have at least one number"; + break; + case ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter: + errorMessage = "Password needs to have at least one special character"; + break; + case ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter: + errorMessage = "Password needs to have at least one uppercase letter"; + break; + case ErrorCode::PasswordsDoNotMatch: + errorMessage = "Passwords do not match"; + break; + default: + errorMessage = "An unkown error occured"; + break; + } +} \ No newline at end of file diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index 320e1d12..e4e96844 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -2,6 +2,7 @@ // Don't forget the header guard - #pragma once #pragma once +#include enum class ErrorCode { Ok, @@ -10,4 +11,6 @@ enum class ErrorCode { PasswordNeedsAtLeastOneSpecialCharacter, PasswordNeedsAtLeastOneUppercaseLetter, PasswordsDoNotMatch -}; \ No newline at end of file +}; + +std::string getErrorMessage(ErrorCode errorCode); \ No newline at end of file From 9fd6e3992c07638b4985618cfce309fe206334b3 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 14:31:20 +0000 Subject: [PATCH 03/11] Add doPasswordsMatch function --- homework/password-check/validation.cpp | 4 ++++ homework/password-check/validation.hpp | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index 5ee6cde2..1eabbbf1 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -28,4 +28,8 @@ std::string getErrorMessage(ErrorCode errorCode) { errorMessage = "An unkown error occured"; break; } +} + +bool doPasswordsMatch(std::string password, std::string repeatedPassword) { + return password == repeatedPassword; } \ No newline at end of file diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index e4e96844..e40c824d 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -13,4 +13,6 @@ enum class ErrorCode { PasswordsDoNotMatch }; -std::string getErrorMessage(ErrorCode errorCode); \ No newline at end of file +std::string getErrorMessage(ErrorCode errorCode); + +bool doPasswordsMatch(std::string password, std::string repeatedPassword); \ No newline at end of file From b64bf0d86dad82acb86d4ad2e7a3bd73b60ef640 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 14:35:22 +0000 Subject: [PATCH 04/11] Add checkPasswordRules function --- homework/password-check/validation.cpp | 4 ++++ homework/password-check/validation.hpp | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index 1eabbbf1..cfc46ad1 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -32,4 +32,8 @@ std::string getErrorMessage(ErrorCode errorCode) { bool doPasswordsMatch(std::string password, std::string repeatedPassword) { return password == repeatedPassword; +} + +ErrorCode checkPasswordRules(std::string password) { + return ErrorCode::Ok; } \ No newline at end of file diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index e40c824d..d8b5d7d4 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -15,4 +15,6 @@ enum class ErrorCode { std::string getErrorMessage(ErrorCode errorCode); -bool doPasswordsMatch(std::string password, std::string repeatedPassword); \ No newline at end of file +bool doPasswordsMatch(std::string password, std::string repeatedPassword); + +ErrorCode checkPasswordRules(std::string password); \ No newline at end of file From 9f763ffe9d415d7327ee9a34098f32ea241fee76 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 14:42:11 +0000 Subject: [PATCH 05/11] Add checkPassword function --- homework/password-check/validation.cpp | 7 +++++++ homework/password-check/validation.hpp | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index cfc46ad1..e383dd86 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -36,4 +36,11 @@ bool doPasswordsMatch(std::string password, std::string repeatedPassword) { ErrorCode checkPasswordRules(std::string password) { return ErrorCode::Ok; +} + +ErrorCode checkPassword(std::string password, std::string repeatedPassowrd) { + if (!doPasswordsMatch(password, repeatedPassowrd)) { + return ErrorCode::PasswordsDoNotMatch; + } + return checkPasswordRules(password); } \ No newline at end of file diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index d8b5d7d4..65125bbe 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -17,4 +17,6 @@ std::string getErrorMessage(ErrorCode errorCode); bool doPasswordsMatch(std::string password, std::string repeatedPassword); -ErrorCode checkPasswordRules(std::string password); \ No newline at end of file +ErrorCode checkPasswordRules(std::string password); + +ErrorCode checkPassword(std::string password, std::string repeatedPassowrd); \ No newline at end of file From c8f09f1814b3e331fab263f2a0993c49d11c4561 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 14:42:58 +0000 Subject: [PATCH 06/11] Clear comments --- homework/password-check/validation.cpp | 1 - homework/password-check/validation.hpp | 3 --- 2 files changed, 4 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index e383dd86..bf1cb19c 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,7 +1,6 @@ #pragma once #include #include "validation.hpp" -// TODO: Put implementations here std::string getErrorMessage(ErrorCode errorCode) { std::string errorMessage{}; diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index 65125bbe..c3a9bbf3 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -1,6 +1,3 @@ -// TODO: I'm empty :) Put enum and function headers here. -// Don't forget the header guard - #pragma once - #pragma once #include From a746dc21111de2df3abead6a319559c31b3303c4 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 14:49:25 +0000 Subject: [PATCH 07/11] Fix pragma once --- homework/password-check/main.cpp | 1 - homework/password-check/validation.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/homework/password-check/main.cpp b/homework/password-check/main.cpp index 1c735999..254ccc11 100644 --- a/homework/password-check/main.cpp +++ b/homework/password-check/main.cpp @@ -1,4 +1,3 @@ -#pragma once #include #include #include "validation.hpp" diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index bf1cb19c..456cb9ea 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,4 +1,3 @@ -#pragma once #include #include "validation.hpp" From 3b40e02272fa9d7f3f174c9d3cfed9cd5f580d8d Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 15:32:04 +0000 Subject: [PATCH 08/11] Add const and reference --- homework/password-check/validation.cpp | 9 +++++---- homework/password-check/validation.hpp | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index 456cb9ea..912a5355 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,7 +1,7 @@ #include #include "validation.hpp" -std::string getErrorMessage(ErrorCode errorCode) { +std::string getErrorMessage(const ErrorCode errorCode) { std::string errorMessage{}; switch(errorCode) { case ErrorCode::Ok: @@ -26,17 +26,18 @@ std::string getErrorMessage(ErrorCode errorCode) { errorMessage = "An unkown error occured"; break; } + return errorMessage; } -bool doPasswordsMatch(std::string password, std::string repeatedPassword) { +bool doPasswordsMatch(const std::string& password, const std::string& repeatedPassword) { return password == repeatedPassword; } -ErrorCode checkPasswordRules(std::string password) { +ErrorCode checkPasswordRules(const std::string& password) { return ErrorCode::Ok; } -ErrorCode checkPassword(std::string password, std::string repeatedPassowrd) { +ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassowrd) { if (!doPasswordsMatch(password, repeatedPassowrd)) { return ErrorCode::PasswordsDoNotMatch; } diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index c3a9bbf3..13616344 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -10,10 +10,10 @@ enum class ErrorCode { PasswordsDoNotMatch }; -std::string getErrorMessage(ErrorCode errorCode); +std::string getErrorMessage(const ErrorCode errorCode); -bool doPasswordsMatch(std::string password, std::string repeatedPassword); +bool doPasswordsMatch(const std::string& password, const std::string& repeatedPassword); -ErrorCode checkPasswordRules(std::string password); +ErrorCode checkPasswordRules(const std::string& password); -ErrorCode checkPassword(std::string password, std::string repeatedPassowrd); \ No newline at end of file +ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassowrd); \ No newline at end of file From ea1b8499ec384b32623f0ea74068082987f4b668 Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 21:34:43 +0000 Subject: [PATCH 09/11] Implement checkPassowordRules function with real validation --- homework/password-check/validation.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index 912a5355..f3f7752e 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "validation.hpp" std::string getErrorMessage(const ErrorCode errorCode) { @@ -34,7 +36,20 @@ bool doPasswordsMatch(const std::string& password, const std::string& repeatedPa } ErrorCode checkPasswordRules(const std::string& password) { - return ErrorCode::Ok; + ErrorCode errorCode{ErrorCode::Ok}; + if (password.size() < 9) { + errorCode = ErrorCode::PasswordNeedsAtLeastNineCharacters; + } + if (std::none_of(password.cbegin(), password.cend(), [](const char c){return std::isdigit(c);})) { + errorCode = ErrorCode::PasswordNeedsAtLeastOneNumber; + } + if (std::none_of(password.cbegin(), password.cend(), [](const char c){return std::ispunct(c);})) { + errorCode = ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter; + } + if (std::none_of(password.cbegin(), password.cend(), [](const char c){return std::isupper(c);})) { + errorCode = ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter; + } + return errorCode; } ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassowrd) { From cedf950e0690f0ac4f6a02523a8162c04ec5cd7a Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 21:55:33 +0000 Subject: [PATCH 10/11] Fix code style to clang-format --- homework/password-check/validation.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index f3f7752e..55312b20 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,11 +1,11 @@ -#include +#include "validation.hpp" #include #include -#include "validation.hpp" +#include std::string getErrorMessage(const ErrorCode errorCode) { std::string errorMessage{}; - switch(errorCode) { + switch (errorCode) { case ErrorCode::Ok: errorMessage = "Ok"; break; @@ -40,13 +40,13 @@ ErrorCode checkPasswordRules(const std::string& password) { if (password.size() < 9) { errorCode = ErrorCode::PasswordNeedsAtLeastNineCharacters; } - if (std::none_of(password.cbegin(), password.cend(), [](const char c){return std::isdigit(c);})) { + if (std::none_of(password.cbegin(), password.cend(), [](const char c) { return std::isdigit(c); })) { errorCode = ErrorCode::PasswordNeedsAtLeastOneNumber; } - if (std::none_of(password.cbegin(), password.cend(), [](const char c){return std::ispunct(c);})) { + if (std::none_of(password.cbegin(), password.cend(), [](const char c) { return std::ispunct(c); })) { errorCode = ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter; } - if (std::none_of(password.cbegin(), password.cend(), [](const char c){return std::isupper(c);})) { + if (std::none_of(password.cbegin(), password.cend(), [](const char c) { return std::isupper(c); })) { errorCode = ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter; } return errorCode; From 68ffbfc47abca494fa21c1a545ab92d9c26445be Mon Sep 17 00:00:00 2001 From: Kajetan Date: Sat, 18 Oct 2025 22:05:20 +0000 Subject: [PATCH 11/11] Fix identation in validation.hpp file to 4 spaces --- homework/password-check/validation.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index 13616344..8cc3310c 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -2,12 +2,12 @@ #include enum class ErrorCode { - Ok, - PasswordNeedsAtLeastNineCharacters, - PasswordNeedsAtLeastOneNumber, - PasswordNeedsAtLeastOneSpecialCharacter, - PasswordNeedsAtLeastOneUppercaseLetter, - PasswordsDoNotMatch + Ok, + PasswordNeedsAtLeastNineCharacters, + PasswordNeedsAtLeastOneNumber, + PasswordNeedsAtLeastOneSpecialCharacter, + PasswordNeedsAtLeastOneUppercaseLetter, + PasswordsDoNotMatch }; std::string getErrorMessage(const ErrorCode errorCode);