diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp index dc3a94c..71d66b6 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/AuthenticationManagementService.cpp @@ -10,6 +10,8 @@ Date:19-May-2026 #include #include "AuthenticationManagementService.h" #include "User.h" +#include "Utility.h" +#include "DataStoreLockGuard.h" User* AuthenticationManagementService::m_authenticatedUser = nullptr; @@ -24,11 +26,12 @@ Return type: bool - true if login successful, false otherwise */ bool AuthenticationManagementService::login(const std::string& username, const std::string& password) { - util::Map users = m_dataStore.getUsers(); - int usersMapSize = users.getSize(); - for (int index = 0; index < usersMapSize; index++) + DataStoreLockGuard lock(m_dataStore); + auto& trackedUserMap = m_dataStore.getUsers(); + int trackedUserMapSize = trackedUserMap.getSize(); + for (int index = 0; index < trackedUserMapSize; index++) { - User* user = users.getValueAt(index); + User* user = trackedUserMap.getValueAt(index).data; if (username == user->getUserName()) { if (password == user->getPassword()) @@ -74,9 +77,18 @@ Return type: void */ void AuthenticationManagementService::changePassword(const std::string& newPassword) { + DataStoreLockGuard lock(m_dataStore); + auto& trackedUsersMap = m_dataStore.getUsers(); if (m_authenticatedUser == nullptr) { throw std::runtime_error("There is no user currently logged in!"); } + int index = trackedUsersMap.find(m_authenticatedUser->getId()); + if (index == -1) + { + throw std::runtime_error("User does not exist!\n"); + } m_authenticatedUser->setPassword(newPassword); + trackedUsersMap.getValueAt(index).state = RecordState::MODIFIED; + m_dataStore.saveUsers(); }