diff --git a/libs/AtmAdmin.h b/libs/AtmAdmin.h index 303a406..5eb909d 100644 --- a/libs/AtmAdmin.h +++ b/libs/AtmAdmin.h @@ -8,6 +8,7 @@ namespace AtmAdmin { char startup(); bool handleUserInformation(char choice, std::string& information); std::string changeAccountPin(); + std::string changeAccountName(); } #endif //ATMADMIN_H diff --git a/src/AtmAdmin.cpp b/src/AtmAdmin.cpp index 2295e2e..a89f09b 100644 --- a/src/AtmAdmin.cpp +++ b/src/AtmAdmin.cpp @@ -1,9 +1,9 @@ -#include -#include "Errorseal.h" -#include "AtmAdmin.h" - #include -#include +#include +#include + +#include "AtmAdmin.h" +#include "Errorseal.h" namespace AtmAdmin { char startup() { @@ -36,8 +36,11 @@ namespace AtmAdmin { // Ensure that the name is also converted to fully lowercase. // The code below is a placeholder - std::cout << "Enter your new username: "; - std::cin >> information; + tempInformation = changeAccountName(); + if (tempInformation != "invalid") { + information = tempInformation; + return true; + } break; case '3': // Simply a way to cheat, very straight-forward. @@ -108,14 +111,25 @@ namespace AtmAdmin { std::string changeAccountName() { std::string newName{}; + std::cout << "Enter new name: "; std::cin >> newName; Error::ignoreLine(); - if (newName.size() < 2 or newName.size() > 10) { + // Ensures the name is between 2 and 10 characters long. + if (newName.length() < 2 or newName.length() > 10) { errorReport("Name has to be between 2 and 10 characters."); return "invalid"; } + + // Checks if the first character is a number. + if (isdigit(newName.at(0))) { + errorReport("First letter cannot be a digit."); + return "invalid"; + } + + // Turns all the letters into lowercase. + std::ranges::transform (newName.cbegin(), newName.cend(), newName.begin(), [] (unsigned char input) { return tolower(input); }); return newName; } -} +} \ No newline at end of file