Implement Change Password

<UserStory> CUS003: Implement change password functionality </UserStory>

<Changes>
    1. Connected Controller::changePassword() with AuthenticationManagementService password update logic.
    2. Added password validation before updating the user password.
    3. Added logged-in user check before allowing password changes.
    4. Implemented password update logic in AuthenticationManagementService.
    5. Added change password flow in CustomerMenu to collect new password input and trigger password update.
    6. Added success message display after password is changed successfully.
</Changes>

<Test>

Change password functionality validation

Precondition:
1. System is running.
2. A registered user exists in the data store.
3. User is logged in and customer menu is active.

Steps:
1. Launch the application and log in with valid credentials.
2. Select the Change Password option from the customer menu.
3. Enter a new password.
   - Verify that the entered password is validated.
4. If the password is valid, complete the password change.
   - Verify that the new password is saved successfully.
   - Verify that the message "Password changed successfully" is displayed.

</Test>

<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
2026-05-19 17:44:38 +05:30
parent 56c5c2dc70
commit cc887b9bc0
4 changed files with 29 additions and 0 deletions
@@ -11,6 +11,7 @@ void Controller::logout()
void Controller::changePassword(const std::string& newPassword)
{
m_authenticationManagementService.changePassword(newPassword);
}
void Controller::createCustomer(const std::string& username, const std::string& password, const std::string& email, const std::string& phone)
@@ -2,6 +2,7 @@
#include "Map.h"
#include <string>
#include "Enums.h"
#include "AuthenticationManagementService.h"
class Service;
class ComboPackage;
@@ -14,6 +15,8 @@ class Notification;
class Controller
{
private:
AuthenticationManagementService m_authenticationManagementService;
public:
bool login(const std::string& username, const std::string& password);
void logout();
@@ -1,3 +1,14 @@
#include <stdexcept>
#include "AuthenticationManagementService.h"
#include "User.h"
User* AuthenticationManagementService::m_authenticatedUser = nullptr;
void AuthenticationManagementService::changePassword(const std::string& newPassword)
{
if (m_authenticatedUser == nullptr)
{
throw std::runtime_error("There is no user currently logged in!");
}
m_authenticatedUser->setPassword(newPassword);
}
@@ -1,6 +1,7 @@
#include "CustomerMenu.h"
#include "InputHelper.h"
#include "OutputHelper.h"
#include "Validator.h"
void CustomerMenu::showMenu()
{
@@ -37,6 +38,19 @@ void CustomerMenu::logout()
void CustomerMenu::changePassword()
{
std::string newPassword;
util::clear();
std::cout << "Enter new password: ";
util::read(newPassword);
m_controller.changePassword(newPassword);
if (!util::isPasswordValid(newPassword))
{
std::cout << "Error: Password is not strong enough!";
util::pressEnter();
return;
}
std::cout << "Password changed successfully";
util::pressEnter();
}
void CustomerMenu::updateDetails()