Password validation program

I am completely lost within the function I have to make a program that has at least 7 to 8 characters on lower case , one upper case and one number can someone help me?
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
 #include <iostream>
#include <cstring>
using namespace std;
int const MAX = 10;
int valid(char*);
int main ()
{
	char pword[MAX];
	bool result;
	cout <<"Password:";
	cin >> pword;
	valid(pword);
	result = valid(pword);
	if (result == true)
		cout <<"Valid password!!\n";
	else 
		cout <<"Wrong password\n";
	return 0;
}
int valid(char* word)
{
	int score = 0;
	int score2 = 0;
	if (strlen(word) < 8)
		cout <<"Sorry not enough";
	for (int x = 0; x < MAX; x++)
	{
		if(isdigit(word != 0))
			score++;
		if(isupper(word != 0))
			score2++;
	}
	if (score > 0 && score2 > 0)
		return true;
} Put the code you need help with here.
Some adjustments:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int valid(char* word)
{
	int score = 0;
	int score2 = 0;
	int len = strlen(word); // Note
	if (len < 8)
		cout <<"Sorry not enough";
	else for (int x = 0; x < len; x++) // Note: Use len instead of MAX
	{
		if(isdigit(word[x]) != 0) // Note
			score++;
		if(isupper(word[x] != 0) // Note
			score2++;
	}
	if (score > 0 && score2 > 0)
		return true;

	return false; // Note
}
Last edited on
Thanks :D i was able to figure it out last night but this also helps thanks :D

#include <iostream>
#include <cstring>
using namespace std;
bool checking(char *);
int main ()
{
char pword[80];
bool result;
cout <<"Please type in password: " ;
cin >> pword;
checking(pword);
result = checking(pword);
if (result == true)
cout <<"Password is valid\n";
else
cout <<"Password is invalid\n";
return 0;
}
bool checking (char * pword)
{
bool upper = false;
bool digit = false;
bool lower = false;
if (strlen(pword) < 5)
return false;
else
{
for (int x = 0; x < strlen(pword);x++)
{
if (isdigit(pword[x])!= 0)
digit = true;
else if (isupper(pword[x])!= 0)
upper = true;
else if(islower(pword[x])!= 0)
lower = true;
}
if (digit && lower&& upper)
return true;
else
return false;
}
}
Topic archived. No new replies allowed.