From 36599fb6219a6e3e121e8418c65d11cef1ee00c3 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 11:47:24 +0200 Subject: [PATCH 01/11] Add ErrorCode enum for password validation --- homework/password-check/validation.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index 85160868..ec553627 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -1,2 +1,10 @@ -// TODO: I'm empty :) Put enum and function headers here. -// Don't forget the header guard - #pragma once \ No newline at end of file +#pragma once + +enum class ErrorCode { + Ok, + PasswordNeedsAtLeastNineCharacters, + PasswordNeedsAtLeastOneNumber, + PasswordNeedsAtLeastOneSpecialCharacter, + PasswordNeedsAtLeastOneUppercaseLetter, + PasswordsDoNotMatch +}; From d9db8e722f721ecb6fb4f09bd7e5dae3c4950f8d Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 12:29:19 +0200 Subject: [PATCH 02/11] Add getErrorMessage function to convert ErrorCode to string --- homework/password-check/validation.cpp | 25 ++++++++++++++++++++++++- homework/password-check/validation.hpp | 5 ++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index a2f12ff3..d94b44b9 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,2 +1,25 @@ #include "validation.hpp" -// TODO: Put implementations here \ No newline at end of file + +std::string getErrorMessage(const ErrorCode code) { + switch (code) { + case ErrorCode::Ok: + return "Ok"; + + case ErrorCode::PasswordNeedsAtLeastNineCharacters: + return "Password Needs At Least Nine Characters"; + + case ErrorCode::PasswordNeedsAtLeastOneNumber: + return "Password Needs At Least One Number"; + + case ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter: + return "Password Needs At Least One Special Character"; + + case ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter: + return "Password Needs At Least One Upper case Letter"; + + case ErrorCode::PasswordsDoNotMatch: + return "Passwords Do Not Match"; + default: + return "Unknown Message"; + } +} diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index ec553627..a3de32b6 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -1,6 +1,7 @@ #pragma once +#include -enum class ErrorCode { +enum class ErrorCode{ Ok, PasswordNeedsAtLeastNineCharacters, PasswordNeedsAtLeastOneNumber, @@ -8,3 +9,5 @@ enum class ErrorCode { PasswordNeedsAtLeastOneUppercaseLetter, PasswordsDoNotMatch }; + +std::string getErrorMessage(const ErrorCode code); \ No newline at end of file From a6b076c66a0597904ff02d1780dd730932019114 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 12:38:23 +0200 Subject: [PATCH 03/11] Reduce ErrorCode size to 1 byte --- homework/password-check/validation.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index a3de32b6..01aed43f 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -1,7 +1,8 @@ #pragma once #include +#include -enum class ErrorCode{ +enum class ErrorCode : uint8_t { Ok, PasswordNeedsAtLeastNineCharacters, PasswordNeedsAtLeastOneNumber, From 8236ed7c75712d5cf70d58ec2b6fa4116802c781 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 12:48:44 +0200 Subject: [PATCH 04/11] Add doPasswordsMatch function --- homework/password-check/validation.cpp | 4 ++++ homework/password-check/validation.hpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index d94b44b9..ddd7ce57 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -23,3 +23,7 @@ std::string getErrorMessage(const ErrorCode code) { return "Unknown Message"; } } + +bool doPasswordsMatch(const std::string& input_pass, const std::string& reference_pass) { + return input_pass == reference_pass; +} diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index 01aed43f..843509f9 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -11,4 +11,5 @@ enum class ErrorCode : uint8_t { PasswordsDoNotMatch }; -std::string getErrorMessage(const ErrorCode code); \ No newline at end of file +std::string getErrorMessage(const ErrorCode code); +bool doPasswordsMatch(const std::string& input_pass, const std::string& reference_pass); From 4719923b39935a26a2c30325979ea84190bf2bc8 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 13:15:47 +0200 Subject: [PATCH 05/11] Add initial checkPasswordRules function Implement the first rule to check if the password has at least 9 characters. --- homework/password-check/validation.cpp | 12 ++++++++++++ homework/password-check/validation.hpp | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index ddd7ce57..2d68524b 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -1,4 +1,6 @@ #include "validation.hpp" +#include +#include std::string getErrorMessage(const ErrorCode code) { switch (code) { @@ -27,3 +29,13 @@ std::string getErrorMessage(const ErrorCode code) { bool doPasswordsMatch(const std::string& input_pass, const std::string& reference_pass) { return input_pass == reference_pass; } + +ErrorCode checkPasswordRules(const std::string& password) { + if (password.size() < 9) { + return ErrorCode::PasswordNeedsAtLeastNineCharacters; + } + + if (!std::any_of(password.begin(), password.end(), [](const char c) { return std::isdigit(c); })) { + return ErrorCode::PasswordNeedsAtLeastOneNumber; + } +} diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index 843509f9..dcb85c3c 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -1,6 +1,6 @@ #pragma once -#include #include +#include enum class ErrorCode : uint8_t { Ok, @@ -13,3 +13,6 @@ enum class ErrorCode : uint8_t { std::string getErrorMessage(const ErrorCode code); bool doPasswordsMatch(const std::string& input_pass, const std::string& reference_pass); + + +ErrorCode checkPasswordRules(const std::string& password); \ No newline at end of file From 3ec28eb07ef928d2d636552f6f0a88471e9801b8 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 13:24:52 +0200 Subject: [PATCH 06/11] Implement rule to check for a number in password --- homework/password-check/validation.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index 2d68524b..cfb4113f 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -34,8 +34,7 @@ ErrorCode checkPasswordRules(const std::string& password) { if (password.size() < 9) { return ErrorCode::PasswordNeedsAtLeastNineCharacters; } - - if (!std::any_of(password.begin(), password.end(), [](const char c) { return std::isdigit(c); })) { + if (std::none_of(password.begin(), password.end(), [](const unsigned char c) { return std::isdigit(c); })) { return ErrorCode::PasswordNeedsAtLeastOneNumber; } } From 14015ecbb402307c743f6578073dceadbd32c45d Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 14:19:58 +0200 Subject: [PATCH 07/11] Add checkPassword function to validate inputs This function checks if passwords match before applying character rules, providing final validation feedback. --- homework/password-check/validation.cpp | 10 +++++++++- homework/password-check/validation.hpp | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index cfb4113f..1742b545 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -34,7 +34,15 @@ ErrorCode checkPasswordRules(const std::string& password) { if (password.size() < 9) { return ErrorCode::PasswordNeedsAtLeastNineCharacters; } - if (std::none_of(password.begin(), password.end(), [](const unsigned char c) { return std::isdigit(c); })) { + if (std::none_of(password.begin(), password.end(), [](const unsigned char c) { return std::isdigit(c); })) { return ErrorCode::PasswordNeedsAtLeastOneNumber; } + return ErrorCode::Ok; +} + +ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassword) { + if (!doPasswordsMatch(password, repeatedPassword)) { + return ErrorCode::PasswordsDoNotMatch; + } + return checkPasswordRules(password); } diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index dcb85c3c..b27a2600 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -14,5 +14,6 @@ enum class ErrorCode : uint8_t { std::string getErrorMessage(const ErrorCode code); bool doPasswordsMatch(const std::string& input_pass, const std::string& reference_pass); +ErrorCode checkPasswordRules(const std::string& password); -ErrorCode checkPasswordRules(const std::string& password); \ No newline at end of file +ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassword); \ No newline at end of file From c073a9e9926dd77000f2a52a9b456cc4360f3ee2 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 14:32:31 +0200 Subject: [PATCH 08/11] Change return text to fit test requirements --- homework/password-check/validation.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index 1742b545..c90ce684 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -8,19 +8,20 @@ std::string getErrorMessage(const ErrorCode code) { return "Ok"; case ErrorCode::PasswordNeedsAtLeastNineCharacters: - return "Password Needs At Least Nine Characters"; + return "Password needs to have at least nine characters"; case ErrorCode::PasswordNeedsAtLeastOneNumber: - return "Password Needs At Least One Number"; + return "Password needs to have at least one number"; case ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter: - return "Password Needs At Least One Special Character"; + return "Password needs to have at least one special character"; case ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter: - return "Password Needs At Least One Upper case Letter"; + return "Password needs to have at least one uppercase letter"; case ErrorCode::PasswordsDoNotMatch: - return "Passwords Do Not Match"; + return "Passwords do not match"; + default: return "Unknown Message"; } From 1162b98b91eb2502857640870bbb56e5516ab612 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 14:38:46 +0200 Subject: [PATCH 09/11] Add rule to check for uppercase letter --- homework/password-check/validation.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index c90ce684..059c42cf 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -38,6 +38,9 @@ ErrorCode checkPasswordRules(const std::string& password) { if (std::none_of(password.begin(), password.end(), [](const unsigned char c) { return std::isdigit(c); })) { return ErrorCode::PasswordNeedsAtLeastOneNumber; } + if (std::none_of(password.begin(), password.end(), [](const unsigned char c) { return std::isupper(c); })) { + return ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter; + } return ErrorCode::Ok; } From d1c02076203e44c85b3d6169c2652f7767513c2b Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 14:47:19 +0200 Subject: [PATCH 10/11] Add rule to check for special characters --- homework/password-check/validation.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index 059c42cf..abbd3335 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -41,6 +41,10 @@ ErrorCode checkPasswordRules(const std::string& password) { if (std::none_of(password.begin(), password.end(), [](const unsigned char c) { return std::isupper(c); })) { return ErrorCode::PasswordNeedsAtLeastOneUppercaseLetter; } + if (std::none_of(password.begin(), password.end(), [](const unsigned char c) { return std::ispunct(c); })) { + return ErrorCode::PasswordNeedsAtLeastOneSpecialCharacter; + } + return ErrorCode::Ok; } From 296f033563574ee649f18c53068e4a3aa41ddfb9 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Sat, 15 Aug 2026 15:07:37 +0200 Subject: [PATCH 11/11] Optimize memory and improve validation security Use std::string_view to avoid heap allocations and add [[nodiscard]] attributes to prevent ignoring return values. --- homework/password-check/validation.cpp | 8 ++++---- homework/password-check/validation.hpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/homework/password-check/validation.cpp b/homework/password-check/validation.cpp index abbd3335..9f1abb24 100644 --- a/homework/password-check/validation.cpp +++ b/homework/password-check/validation.cpp @@ -2,7 +2,7 @@ #include #include -std::string getErrorMessage(const ErrorCode code) { +std::string_view getErrorMessage(const ErrorCode code) { switch (code) { case ErrorCode::Ok: return "Ok"; @@ -27,11 +27,11 @@ std::string getErrorMessage(const ErrorCode code) { } } -bool doPasswordsMatch(const std::string& input_pass, const std::string& reference_pass) { +bool doPasswordsMatch(const std::string_view& input_pass, const std::string_view& reference_pass) { return input_pass == reference_pass; } -ErrorCode checkPasswordRules(const std::string& password) { +ErrorCode checkPasswordRules(const std::string_view& password) { if (password.size() < 9) { return ErrorCode::PasswordNeedsAtLeastNineCharacters; } @@ -48,7 +48,7 @@ ErrorCode checkPasswordRules(const std::string& password) { return ErrorCode::Ok; } -ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassword) { +ErrorCode checkPassword(const std::string_view& password, const std::string_view& repeatedPassword) { if (!doPasswordsMatch(password, repeatedPassword)) { return ErrorCode::PasswordsDoNotMatch; } diff --git a/homework/password-check/validation.hpp b/homework/password-check/validation.hpp index b27a2600..95ae054d 100644 --- a/homework/password-check/validation.hpp +++ b/homework/password-check/validation.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include enum class ErrorCode : uint8_t { Ok, @@ -11,9 +11,9 @@ enum class ErrorCode : uint8_t { PasswordsDoNotMatch }; -std::string getErrorMessage(const ErrorCode code); -bool doPasswordsMatch(const std::string& input_pass, const std::string& reference_pass); +[[nodiscard]] std::string_view getErrorMessage(const ErrorCode code); +[[nodiscard]] bool doPasswordsMatch(const std::string_view& input_pass, const std::string_view& reference_pass); -ErrorCode checkPasswordRules(const std::string& password); +[[nodiscard]] ErrorCode checkPasswordRules(const std::string_view& password); -ErrorCode checkPassword(const std::string& password, const std::string& repeatedPassword); \ No newline at end of file +[[nodiscard]] ErrorCode checkPassword(const std::string_view& password, const std::string_view& repeatedPassword); \ No newline at end of file