For this test set, the old password only satisfies requirements
string createNewPassword(string oldPassword) {
string newPassword = oldPassword;
newPassword.append("a"); // Append any lowercase English alphabet letter.
newPassword.append("B"); // Append any uppercase English alphabet letter.
newPassword.append("&"); // Append any special character.
return newPassword;
}
To solve this test set, we can loop through the old password and check which of
the given requirements are unsatisfied. For each unsatisfied requirements
between
string createNewPassword(string oldPassword) {
bool condition2 = false;
bool condition3 = false;
bool condition4 = false;
bool condition5 = false;
string newPassword = oldPassword;
for (int i = 0; i < oldPassword.size(); i++) {
if (oldPassword[i] >= 'A' && oldPassword[i] <= 'Z')
condition2 = true;
else if (oldPassword[i] >= 'a' && oldPassword[i] <= 'z')
condition3 = true;
else if (oldPassword[i] >= '0' && oldPassword[i] <= '9')
condition4 = true;
else if (oldPassword[i] == '@' || oldPassword[i] == '#' || oldPassword[i] == '&' || oldPassword[i] == '*')
condition5 = true;
}
if (!condition2) newPassword.append("A"); // Append any uppercase English alphabet letter.
if (!condition3) newPassword.append("a"); // Append any lowercase English alphabet letter.
if (!condition4) newPassword.append("1"); // Append any digit.
if (!condition5) newPassword.append("#"); // Append any special character.
// Append any digit, letter, or a special character.
while (newPassword.size() < 7) newPassword.append("1");
return newPassword;
}