password verifier

I have a homework assignment that requires me to write a program that asks for a password and checks to see if it is acceptable.
The requirements for a good password are as follows:
1. must be at least 6 characters
2. must have at least one uppercase letter
3. must have at least one lowercase letter
4. must have at least one digit

My program successfully compiles but it seems like it gets stuck in the loop when I try to run it and It can't get past the length test.

here is what I have so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Password Verifier
#include<iostream>
#include<string>
#include<cctype>
#include<cstring>
using namespace std;
int main()
{
string password;
int length;
bool acceptable=false;
bool upper=false;
bool lower=false;
bool digit=false;
do
{
cout<<"Enter a password.\n";
getline(cin, password);
length=password.length();
if(length<6)
{
cout<<"Error! Your password must be at least 6 characters\n";
}
for(int i=0; i<length; i++)
{
	if(isupper(password[i]))
	{
	upper=true;
	}
	if(islower(password[i]))
	{
	lower=true;
	}
	if(isdigit(password[i]))
	{
	digit=true;
	}
}
if(upper==true && lower==true && digit==true)
{
acceptable=true;
}
}
while(acceptable==false);
cout<<"Your password is acceptable.\n";
return 0;
}
One problem that I see is that you don't reset upper, lower and digit back to false on each pass through the do/while loop. If the user entered a password with an upper but not a lower on the first attempt, upper would be set to true. If the second attempt had no upper case letter, upper is still set to true.
Thanks for the tip. I fixed that part. Can you see what would be causing the issue that gets it stuck in the loop at the length test? This is what happens when running it:

output: Enter a password
input: ggg
output: Error! your password must be at least 6 characters.
output: Enter a password
input: ggggggg
output: Enter a password

It will give the error message if the password is not long enough but other than that it's stuck in the loop and asks for a password over and over.
I think your program is working correctly.

Consider adding an else clause at line 42
42
43
44
45
46
47
    if(upper==true && lower==true && digit==true)
    {   acceptable=true;
    }
    else
    {  cout << "Your password is not acceptable" << endl;
    }


If the password is not acceptable, you should now get a message and loop back to prompt for another attempt.
Thank you! The problem was that I forgot to include an error message for the other conditions so that's why it seemed like it was stuck. Sorry about that, I really should've been able to catch that myself.
Topic archived. No new replies allowed.