having trouble with checking a password for a lower case letter

I wrote code to test for different requirements for a password. I can get most of the requirements to work except for the lowercase letter requirement it shows up for all passwords even if it has a lowercase letter.

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  #include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <fstream>

using namespace std;

bool isSpecial (char ch)
{
	bool status=true;
	if (isalpha (ch)== true)
	{
		status=false;
	}
	else if (isdigit (ch)== true)
	{
		status=false;
	}
	return status;
}

int main()
{
	ifstream infile;
	infile.open ("password.txt");
	if (infile.fail())
	{
		cout<<"input file did not open"<<endl;
		exit (-1);
	}
	int total=0;
	int valid=0;
	int invalid=0;
	bool password;
	char ch;
	ch=infile.get();
	while (infile)
	{
		int lc=0;
		int upL=0;
		int sp=0;
		int num=0;
		int length=0;
		while (ch!='\n')
		{
			if (isupper(ch)==true)
			{
				upL++;
			}
			if (isdigit(ch)==true)
			{
				num++;
			}
			if (isSpecial (ch)==true)
			{
				sp++;
			}
			if (islower(ch)==true)
			{
				lc++;
			}
			cout<<ch;
			length++;
			ch=infile.get();
		}
		if (upL==0)
		{
			password=false;
			cout<<endl<<"Missing Uppercase Letter"<<endl;
		}
		if (num==0)
		{
			password=false;
			cout<<endl<<"Missing Number"<<endl;
		}
		if (sp==0)
		{
			password=false;
			cout<<endl<<"Missing Special Character"<<endl;
		}	
		if (lc==0)
		{
			password=false;
			cout<<endl<<"Missing Lowercase Letter"<<endl;
		}
		if (length<6)
		{
			password=false;
			cout<<endl<<"Not Enough Characters"<<endl;
		}
		if (password==true)
		{
			cout<<endl<<"Valid Password"<<endl;
			valid++;
		}
		else
		{
			invalid++;
		}
		total++;
		ch=infile.get();
	}
	infile.close();
	cout<<"Total Number Of Passwords: "<<total<<endl;
	cout<<"		Valid: "<<valid<<endl;
	cout<<"		Invalid: "<<invalid<<endl;
	return 0;
}



It pulls from a file that has various passwords the test of the file is below.

1
2
3
4
5
6
abc123
ABCDEFG
Abc123
Ab1
Abc123#
#@ABC1234 
closed account (1vD3vCM9)
Try placing "else if" instead of "if", like
1
2
3
4
5
6
7
if(pingas == false){

}else if(pingas == true){

}else{

}

I can't check the code and try to help more as I'm not home
thanks i got it working this is what i used
[code]
while (ch!='\n')
{
if (isalpha(ch))
if (islower(ch))
{
lc++;
}
else
{
upL++;
}
if (isdigit(ch))
{
num++;
}
if (isSpecial (ch))
{
sp++;
}
cout<<ch;
length++;
ch=infile.get();
}
cout<<endl;
if (upL==0)
{
password=false;
cout<<"Missing Uppercase Letter"<<endl;
}
if (num==0)
{
password=false;
cout<<"Missing Number"<<endl;
}
if (sp==0)
{
password=false;
cout<<"Missing Special Character"<<endl;
}
if (lc==0)
{
password=false;
cout<<"Missing Lowercase Letter"<<endl;
}
if (length<6)
{
password=false;
cout<<"Not Enough Characters"<<endl;
}
if (password==true)
{
cout<<"Valid Password"<<endl;
valid++;
}
else
{
invalid++;
}
total++;
ch=infile.get();
}
[\code]
You need to reset your password variable for each line in the file.

Also look at this snippet:

1
2
if (password==true)
		{

You really don't need the comparison in this if statement. All you should need is:

1
2
if(password)
{
Topic archived. No new replies allowed.