I was assigned to write a program that will verify a password entered by the user. The program should verify that the password has 6-10 characters and atleast 1 uppercase, 1 lowercase, and 1 numeric digit. The program runs, but will only display the length of the password entered and won't verify any of the input.
I'm completely lost on how to get my verifyPass() function to work properly and am probably taking the wrong approach to verifying. Please help!
here's the code
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
//function prototypes
bool verifyPass(char []);
const int LENGTH = 11;
int main()
{
char password[LENGTH];
cout << "Enter a password with the following criteria:\n";
cout << "6-10 characters\n";
cout << "1 uppercase\n1 lowercase\n1 numeric digit\n";
cout << "(ex. xxXx1x, Aaaaa2): ";
cin.getline(password, LENGTH);
if(verifyPass(password))
cout << "That is a valid password\n";
else
cout << "That is an invalid password\n";
system("pause");
return 0;
}
bool verifyPass(char pw[])
{
int length;
length = strlen(pw);
if(length >= 6 && length <=10)
{
for (int count = 0; count < LENGTH; count++)
{
while (!islower(pw[count]))
return false;
}
for (int count = 0; count < LENGTH; count++)
{
while (!isdigit(pw[count]))
return false;
}
for (int count = 0; count < LENGTH; count++)
{
while (!isupper(pw[count]))
return false;
}
}
else
cout << "Must enter a password 6-10 characters long\n";
return true;
}