Added more checks for changeAccountPin()

This commit is contained in:
theskywinds 2025-06-04 12:18:52 +02:00
parent dbe1063f29
commit 6ba17abcb1

View File

@ -71,6 +71,12 @@ namespace AtmAdmin {
std::cin >> newPin;
Error::ignoreLine();
std::array<int, 4> pinDigits{};
for (size_t i{}; i != 4; i++) {
pinDigits[i] = (newPin[i] - '0');
}
if (newPin.size() != 4) {
errorReport("The pin has to be 4 numbers long.");
return "invalid";
@ -89,7 +95,24 @@ namespace AtmAdmin {
}
}
{ // Start of bracket scope
// Checks for sequential numbers (examples: 1234, 6789)
{ // START OF BRACKET SCOPE //
int sequentialCount {0};
for (size_t i{0}; i < 3; i++) {
if (pinDigits[i]+1 == pinDigits[i+1] or pinDigits[i]-1 == pinDigits[i+1])
sequentialCount += 1;
if (sequentialCount == 3) {
errorReport("Pin is too simple.");
return "invalid";
}
}
} // END OF BRACKET SCOPE //
// Checks for too many duplicate numbers.
{ // START OF BRACKET SCOPE //
std::string tempPin = newPin;
std::ranges::sort(tempPin.begin(), tempPin.end());
@ -103,7 +126,7 @@ namespace AtmAdmin {
errorReport("Too many duplicate numbers.");
return "invalid";
}
} // End of bracket scope
} // END OF BRACKET SCOPE //
return newPin;
}