I am trying to write a program which includes a three stage password.
The user is prompted with a question that has a single word answer. They must input the correct string to proceed to the second question, and again to reach the third.
In order to verify that the user has entered the correct code, I use the string compare function. However, the second or third stages frequently fail to correctly compare the input password to the correct existing password. The code is allowing the user to progress to the third stage regardless of what they enter as string 2.
One complexity added is that there are multiple accepted passwords to allow for flexibility with the input, such as the capitalization of the first character in the string.
Example code is provided below:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
string name, trueName1, trueName2;
string trueName1= "John";
string trueName2= "john";
cout<< "Stage 1:" <<endl;
Sleep(1000);
cout<< "Enter first name: ";
cin>> name;
if ((name.compare(trueName1) == 1) && (name.compare(trueName2) ==1) )
{
cout<<"Error - ID mismatch" <<endl;
return 0;
}
|
This will work once, sometimes even twice in a row, but very frequently the second or third stage will fail to present any error, and allows the user to pass by entering any string.
Any suggestion as to what my issue might be would be greatly appreciated.
-Luki