I have been working on this problem for a while and I cannot get the program to accept my arguments. The problem requires a password to be at least six characters long, have at least 1 lower and uppercase letter, and 1 digit. The program should verify if password is acceptable or not. I do not have any error messages, but the program does not work when the listed criteria is entered. Here is what I coded:
/*******************************
Password Verifier
*******************************/
# include <iostream> // i/o header file
# include <cctype> // header file needed for testing characters (e.g., isupper())
# include <cstring> //header file needed for using strlen() function
usingnamespace std;
bool testUpper (char []); //function prototype for function testUpper
bool testLower (char []); //function prototype for function testLower
bool testDigit (char []); //function prototype for function testDigit
bool pswordVerify(char []); // function prototype for function pswordVerify
/****************************
Function Main
*****************************/
int main ()
{
constint LENGTH = 100; // Maximum length of string
char password[LENGTH]; // array allows up to 100 characters for a password
//Program Introduction
cout << "PASSWORD VERIFICATION\n\n";
cout << "Please create a password using only 6 characters. ";
cout << "The password must contain at\nleast 1 uppercase letter, ";
cout << "1 lowercase letter, and 1 digit.\n";
cin.getline(password, LENGTH); //user enters password
// Congratulatory message if passoword is valid
if (pswordVerify(password))
cout << "Password accepted!\n";
//Loops error message while password is invalid
while (!pswordVerify(password))
{
cout << "please enter a valid entry.\n";
cout << "A valid password requires at least the following:\n\n";
cout << "A password must be at least 6 characters. ";
cout << "1 uppercase letter, 1 lowercase\nletter, and 1 digit ";
cout << "(0 through 9).\n";
cin.getline(password, LENGTH); //user reenters password
}
return 0;
}
/************************************************************
Function pswordVerify is used to verify the characters
enter has at least 1 digit, 1 lowercase letter, and 1
upercase letter. The password must be at least 6 characters
long
*************************************************************/
bool pswordVerify(char psword [])
{
bool result =false;
int length = strlen(psword);
testUpper(psword);
testLower (psword);
testDigit (psword);
result = testUpper(psword) && testLower(psword) && testDigit(psword) && (length>=6);
return result;
}
/****************************************************
Function testUpper is used to verify at least 1
uppercase letter is used in the user's password.
*****************************************************/
bool testUpper (char psword [])
{
int length = strlen(psword);
int count;
for (count = 0; count < length; count++)
{
if (!isupper (psword[count]))
returnfalse;
}
returntrue;
}
/****************************************************
Function testLower is used to verify at least 1
lowercase letter is used in the user's password.
*****************************************************/
bool testLower (char psword [])
{
int length = strlen(psword);
int count;
for (count = 0; count < length; count++)
{
if (!islower (psword[count]))
returnfalse;
}
returntrue;
}
/****************************************************
Function testDigit is used to verify at least 1
digit is used in the user's password.
*****************************************************/
bool testDigit (char psword [])
{
int length = strlen(psword);
int count;
for (count = 0; count < length; count++)
{
if (!isdigit (psword[count]))
returnfalse;
}
returntrue;
}
Ok, I have it solved. I got some help on another board. Changed the !isupper and the likes to issupper and tested true instead of false. This fixed my problem. If anyone needs me to post my results just reply here. Thanks.
May I note that your "Congratulatory message if passoword is valid" will only show if the password is entered correctly on the very first go... Just remove the if and put the statement on it's own underneith the while loop before the program exits.
Also you don't need to call all the functions in pswordVerify(...), just remove them and leave but leave the function calls in the variable assignment.