I'm writing a program that validates a password entered by the user. The password has to contain some characters including *
The problem is that the program has to terminate when the user enters the single character * and I'm stuck on this part. How do I do it? Any feedback is appreciated. Here's my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
do
{
cout << "please enter a password with the following rules: " << endl << endl;
........
cin.getline(passName, 21);
cout << endl << endl;
passLen = strlen(passName);
for (int i = 0; passName[i]; i++)
{
if (passName[i] == '*') // i know that this code checks if the password contains the character *.
return 0;
}
....
} while(passName[len] != '*');
for (int i = 0; passName[i]; i++)
{
if (passName[i] == '*') // i know that this code checks if the password contains the character *.
return 0;
}
That exits your function (and the program?) when it sees any * character. That doesn't make sense since you say that the password must contain * characters. Or am I misunderstanding the problem?
At any rate, you said the program should exit if a single * character is entered as the password, but otherwise it should keep running. The way you have that coded, a password such as fd24^*K would also cause the program to stop running.
A signle character as in if the user only enters * and that's it. For example, If the user enters jj*, the program doesn't terminate and only shows an error message saying the password is too short. However, if the user enters only *, then the program should terminate. How would I do that?