From 1c22c14f3278580c31f6c2b4c0d6a61a187bddbc Mon Sep 17 00:00:00 2001 From: Princy Jerin Date: Mon, 6 Apr 2026 15:06:55 +0530 Subject: [PATCH] Add reset initial password AUTH002 : Reset Initial Password - Added logic for resetting initial password - Code Cleanup Smitha Mohan --- .../Trenser.Zenvy.vcxproj.filters | 15 +++---- .../controllers/ZenvyController.cpp | 2 +- .../controllers/ZenvyController.h | 4 +- .../AuthenticationManagementService.h | 2 +- .../Trenser.Zenvy/utilities/Validator.cpp | 43 +++++++++++++++++++ .../Trenser.Zenvy/utilities/Validator.h | 1 + .../Trenser.Zenvy/views/UserInterface.cpp | 18 ++++++-- 7 files changed, 67 insertions(+), 18 deletions(-) diff --git a/Trenser.Zenvy/Trenser.Zenvy/Trenser.Zenvy.vcxproj.filters b/Trenser.Zenvy/Trenser.Zenvy/Trenser.Zenvy.vcxproj.filters index c4168cc..8a20aa6 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/Trenser.Zenvy.vcxproj.filters +++ b/Trenser.Zenvy/Trenser.Zenvy/Trenser.Zenvy.vcxproj.filters @@ -174,9 +174,6 @@ Views - - Views - Views @@ -192,6 +189,9 @@ Models + + Services + @@ -320,12 +320,6 @@ Views - - Views - - - Views - Views @@ -341,6 +335,9 @@ Models + + Services + diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp index 39d42dd..1f26894 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.cpp @@ -11,7 +11,7 @@ void ZenvyController::logout() m_authenticationManagementService->logout(); } -void ZenvyController::changePassword(const std::string& password) const +void ZenvyController::changePassword(const std::string& password) { m_authenticationManagementService->changePassword(password); } diff --git a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h index 6413723..11a609d 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h +++ b/Trenser.Zenvy/Trenser.Zenvy/controllers/ZenvyController.h @@ -44,7 +44,5 @@ public: //Authentication AuthenticationContext login(const std::string& email, const std::string& password); void logout(); - void changePassword(const std::string&) const; + void changePassword(const std::string&); }; - - diff --git a/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h b/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h index 9c65eae..2f812d6 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h +++ b/Trenser.Zenvy/Trenser.Zenvy/services/AuthenticationManagementService.h @@ -14,6 +14,6 @@ public: AuthenticationManagementService() : m_dataStore(DataStore::getInstance()) {}; std::tuple login(const std::string& username, const std::string& password); void logout(); - void changePassword(std::string); + void changePassword(const std::string&); }; diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp index fa7707e..f6c4306 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.cpp @@ -1,4 +1,7 @@ +#include +#include #include "Validator.h" +#include "ApplicationConfig.h" bool util::isPhoneNumberValid(const std::string& phoneNumber) { if (phoneNumber.size() != 10) @@ -26,3 +29,43 @@ bool util::isEmailValid(const std::string& email) { } return true; } + + +bool util::isPasswordValid(const std::string& password) +{ + if (password == Config::DEFAULT_PASSWORD) + { + return false; + } + if (password.length() < 8) + return false; + bool hasUpper = false; + bool hasLower = false; + bool hasDigit = false; + bool hasSpecial = false; + + for (char character : password) + { + if (std::isspace(static_cast(character))) + { + return false; + } + if (std::isupper(static_cast(character))) + { + hasUpper = true; + } + else if (std::islower(static_cast(character))) + { + hasLower = true; + } + else if (std::isdigit(static_cast(character))) + { + hasDigit = true; + } + else + { + hasSpecial = true; + } + } + return hasUpper && hasLower && hasDigit && hasSpecial; +} diff --git a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h index d5fd36d..fbdf962 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h +++ b/Trenser.Zenvy/Trenser.Zenvy/utilities/Validator.h @@ -7,4 +7,5 @@ namespace util { bool isPhoneNumberValid(const std::string&); bool isEmailValid(const std::string&); + bool isPasswordValid(const std::string&); } \ No newline at end of file diff --git a/Trenser.Zenvy/Trenser.Zenvy/views/UserInterface.cpp b/Trenser.Zenvy/Trenser.Zenvy/views/UserInterface.cpp index c320701..3bc4e6e 100644 --- a/Trenser.Zenvy/Trenser.Zenvy/views/UserInterface.cpp +++ b/Trenser.Zenvy/Trenser.Zenvy/views/UserInterface.cpp @@ -14,6 +14,7 @@ #include "ZenvyController.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Validator.h" void UserInterface::run() { @@ -82,11 +83,20 @@ void UserInterface::login() if (loginStatus == Enums::LoginStatus::FIRST_LOGIN) { util::clear(); - std::cout - << "Warning: You're using the default password!\n" + std::cout << "Warning: You're using the default password!\n" << "Please change it.\n"; - // TODO: Password reset flow (to be implemented) - util::pressEnter(); + std::cout << "Enter new password: \n"; + util::read(password); + if (util::isPasswordValid(password)) + { + m_controller->changePassword(password); + } + else + { + std::cout << "\nInvalid Password"; + util::pressEnter(); + return; + } } util::clear(); // Route to appropriate menu