Implement Change Password Functionality
<UserStory> ADM005: Change Password </UserStory>
<Changes>
1. Added AuthenticationManagementService::changePassword to update the authenticated user’s password with validation.
2. Integrated Controller::changePassword to delegate password update requests to AuthenticationManagementService.
3. Enhanced AdminMenu::changePassword to prompt for new password, validate strength using Validator, and confirm update.
4. Added error handling to prevent password change when no user is logged in.
5. Provided user feedback messages for invalid password attempts and successful updates.
</Changes>
<Test>
Precondition:
1. Admin is logged into the system.
2. AuthenticationManagementService maintains active session.
3. Validator is available for password strength checks.
Steps:
1. Navigate to Admin Menu and select "Change Password".
2. Enter old password incorrectly.
- Verify that system rejects the attempt and displays error.
3. Enter new password that fails validation (length/complexity).
- Verify that system rejects with "Error: Password is not strong enough!".
4. Enter valid old password and strong new password.
- Verify that system confirms "Password changed successfully" and updates the user’s password.
</Test>
<Review>
Sreeja Reghukumar
</Review>
This commit is contained in:
@@ -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();
|
||||
|
||||
+10
@@ -1,3 +1,13 @@
|
||||
#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 "AdminMenu.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "Validator.h"
|
||||
|
||||
void AdminMenu::showMenu()
|
||||
{
|
||||
@@ -38,6 +39,23 @@ void AdminMenu::logout()
|
||||
|
||||
void AdminMenu::changePassword()
|
||||
{
|
||||
std::string newPassword;
|
||||
while (true)
|
||||
{
|
||||
util::clear();
|
||||
std::cout << "Enter new password: ";
|
||||
util::read(newPassword);
|
||||
if (!util::isPasswordValid(newPassword))
|
||||
{
|
||||
std::cout << "Error: Password is not strong enough!\n";
|
||||
util::pressEnter();
|
||||
continue;
|
||||
}
|
||||
m_controller.changePassword(newPassword);
|
||||
std::cout << "Password changed successfully\n";
|
||||
util::pressEnter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AdminMenu::viewStockLevels()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "TechnicianMenu.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "Validator.h"
|
||||
|
||||
void TechnicianMenu::showMenu()
|
||||
{
|
||||
@@ -38,3 +39,24 @@ void TechnicianMenu::completeJob()
|
||||
void TechnicianMenu::viewNotifications()
|
||||
{
|
||||
}
|
||||
|
||||
void TechnicianMenu::changePassword()
|
||||
{
|
||||
std::string newPassword;
|
||||
while (true)
|
||||
{
|
||||
util::clear();
|
||||
std::cout << "Enter new password: ";
|
||||
util::read(newPassword);
|
||||
if (!util::isPasswordValid(newPassword))
|
||||
{
|
||||
std::cout << "Error: Password is not strong enough!\n";
|
||||
util::pressEnter();
|
||||
continue;
|
||||
}
|
||||
m_controller.changePassword(newPassword);
|
||||
std::cout << "Password changed successfully\n";
|
||||
util::pressEnter();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,5 @@ public:
|
||||
void showMenu();
|
||||
void completeJob();
|
||||
void viewNotifications();
|
||||
void changePassword();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user