Add reset initial password

<UserStory> AUTH002 : Reset Initial Password </UserStory>

    <Changes>
    - Added logic for resetting initial password
    - Code Cleanup
    </Changes>

    <Review>
    Smitha Mohan
    </Review>
This commit is contained in:
Princy Jerin
2026-04-06 15:06:55 +05:30
committed by Joel Thomas
parent fdd90636ed
commit 1c22c14f32
7 changed files with 67 additions and 18 deletions
@@ -174,9 +174,6 @@
<ClCompile Include="views\ITExecutiveMenu.cpp">
<Filter>Views</Filter>
</ClCompile>
<ClCompile Include="views\MainMenu.cpp">
<Filter>Views</Filter>
</ClCompile>
<ClCompile Include="views\TalentExecutiveMenu.cpp">
<Filter>Views</Filter>
</ClCompile>
@@ -192,6 +189,9 @@
<ClCompile Include="models\Faq.cpp">
<Filter>Models</Filter>
</ClCompile>
<ClCompile Include="services\ApplicationConfig.cpp">
<Filter>Services</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="services\AuthenticationManagementService.h">
@@ -320,12 +320,6 @@
<ClInclude Include="views\ITExecutiveMenu.h">
<Filter>Views</Filter>
</ClInclude>
<ClInclude Include="views\MainMenu.h">
<Filter>Views</Filter>
</ClInclude>
<ClInclude Include="views\Menu.h">
<Filter>Views</Filter>
</ClInclude>
<ClInclude Include="views\TalentExecutiveMenu.h">
<Filter>Views</Filter>
</ClInclude>
@@ -341,6 +335,9 @@
<ClInclude Include="models\Faq.h">
<Filter>Models</Filter>
</ClInclude>
<ClInclude Include="services\ApplicationConfig.h">
<Filter>Services</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude Include="models\Employee.h">
@@ -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);
}
@@ -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&);
};
@@ -14,6 +14,6 @@ public:
AuthenticationManagementService() : m_dataStore(DataStore::getInstance()) {};
std::tuple<Enums::LoginStatus, Enums::EmployeeType, Enums::EmployeeDesignation> login(const std::string& username, const std::string& password);
void logout();
void changePassword(std::string);
void changePassword(const std::string&);
};
@@ -1,4 +1,7 @@
#include <string>
#include <cctype>
#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<unsigned char>(character)))
{
return false;
}
if (std::isupper(static_cast<unsigned char>(character)))
{
hasUpper = true;
}
else if (std::islower(static_cast<unsigned char>(character)))
{
hasLower = true;
}
else if (std::isdigit(static_cast<unsigned char>(character)))
{
hasDigit = true;
}
else
{
hasSpecial = true;
}
}
return hasUpper && hasLower && hasDigit && hasSpecial;
}
@@ -7,4 +7,5 @@ namespace util
{
bool isPhoneNumberValid(const std::string&);
bool isEmailValid(const std::string&);
bool isPasswordValid(const std::string&);
}
@@ -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)
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