Building a password verification program. I am having difficulty making my logic produce the correct outputs. Very basic code, but really giving me fits, sadly I have a few hours already into this. The out puts are wrong a given code. I believe the " must include a digit" test is functioning well, but testing for an upper case and lower case is definitely incorrect.
Thanks for taking a peak.
#include <cctype>
#include <cstring>
#include <iostream>
using namespace std;
// Function prototype............verify the password.
bool validPassword(char[]);
void main()
{
const int Array_Size = 20;
char password[Array_Size];
cout << "Please enter your password, and I will VERIFY" << endl;
cin.getline(password, Array_Size);
validPassword(password); //call function
system("pause");
}
bool validPassword(char password[])
{
bool upperLower = false;
bool includeNum = false;
int length;
length = strlen(password); //length of string
if (length < 6)
cout << "Invalid Password. Password Should Be Six Characters long!" << endl;
for (int i = 0; i < length; i++)
{
if (isupper(password[i]) || (islower(password[i]))) //isupper,islower found on pg 542 of text.
upperLower = true; //tests each letter for upper and lower case
if (isdigit(password[i])) //step thru, test each character for presence of digit. text pg 542
includeNum = true;
}
if (!upperLower)
cout << "Invalid Password. Please Include At Least One Upper Case And One Lower Case Letter." << endl; // only returns true if both are present
if (!includeNum)
cout << "Invalid Password. Please Include A Number." << endl;
if ((includeNum = true) && (upperLower = true))
cout << "This password passes the verification criteria." << endl;
tried hard to make corrections, am I on the right path? My logic is still corrupt, as I am not getting the warnings I expected with no lowercase or no uppercase.
#include <cctype>
#include <cstring>
#include <iostream>
usingnamespace std;
// Function prototype............verify the password.
bool validPassword(char[]);
bool main()
{
constint Array_Size = 20;
char password[Array_Size];
bool pass=false;
cout << "Please enter your password, and I will VERIFY" << endl;
cin.getline(password, Array_Size);
//if (validPassword(password)==true); //call function
//cout << "This password is acceptable!" << endl;
validPassword(password);
if (pass)
cout << "This password is acceptable!" << endl;
system("pause");
}
bool validPassword(char password[])
{
bool pass = true;
bool upperLower = false;
bool includeNum = false;
int length;
length = strlen(password); //length of string
if (length < 6)
cout << "Invalid Password. Password Should Be Six Characters long!" << endl;
for (int i = 0; i < length; i++)
{
if (isupper(password[i]) || (islower(password[i]))) //isupper,islower found on pg 542 of text.
upperLower = true; //tests each letter for upper and lower case
if (isdigit(password[i])) //step thru, test each character for presence of digit. text pg 542
includeNum = true;
}
if (!upperLower)
cout << "Invalid Password. Please Include At Least One Upper Case And One Lower Case Letter." << endl; // only returns true if both are present
if (!includeNum)
cout << "Invalid Password. Please Include A Number." << endl;
if ((includeNum == true) && (upperLower == true))
return pass=true;
elsereturn 0;
}
Thanks for taking a look.
PS thanks for the heads up with regard to code blocks....