//Saliha Babar CS1A Chapter 10, #12, Page 590
//
/****************************************************************************
* VERIFY PASSWORD
* ___________________________________________________________________________
* This program accepts string and determines whether that string meet certain
* password requirements.
*
* The requirements include
* at least 6 characters, at least one upper case & one lowercase & one digit
* ____________________________________________________________________________
* INPUT
* SIZE : maximum size of password
* password : array of characters
*
* OUTPUT
* lengthCheck : check for string length
* upperCheck : check for uppercase letter
* lowerCheck : check for lowercase letter
* digitCheck : check for digits
* **************************************************************************/
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
bool CheckLength(char array[], int SIZE);
bool CheckUpper (char array[], int SIZE);
bool CheckLower (char array[], int SIZE);
bool CheckDigit (char array[], int SIZE);
int main() {
const int SIZE = 15; // INPUT - maximum size of string
char password[SIZE]; // INPUT - array to hold characters
bool tryAgain = true ; // Check for overall criteria
bool lengthCheck; // Check for string length
bool upperCheck; // Check for uppercase letter
bool lowerCheck; // Check for lowercase letter
bool digitCheck; // Check for digits
cout << "Enter a password up to " <<SIZE-1<< " characters that includes\n";
cout << "at least 6 characters\n";
cout << "at least one uppercase and one lowercase\n";
cout << "at least one digit\n";
while (tryAgain)
{
cout << "Enter the password as you wish.\n";
cin.getline (password, SIZE);
lengthCheck = CheckLength (password, SIZE);
upperCheck = CheckUpper (password, SIZE);
lowerCheck = CheckLower (password, SIZE);
digitCheck = CheckDigit (password, SIZE);
tryAgain = lengthCheck || upperCheck || lowerCheck || digitCheck;
}
cout << "Your password meets the criteria & verified..\n";
return 0;
}
bool CheckLength(char array[],int SIZE)
{
if (strlen(array) < 6)
{
cout << "You did not entered password with at least 6 characters.\n";
return true;
}
else
return false;
}
bool CheckUpper (char array[], int SIZE)
{
for (int i = 0; i < SIZE ; i++)
{
if (isupper(array[i]))
return false;
}
cout << "Your password doesnt contain at least one UpperCase letter\n";
return true;
}
bool CheckLower (char array[], int SIZE)
{
for (int i = 0; i < SIZE ; i++)
{
if (islower(array[i]))
return false;
}
cout << "Your password doesnt contain at least one lowercase letter\n";
return true;
}
bool CheckDigit (char array[], int SIZE)
{
for (int i = 0; i < SIZE ; i++)
{
if (isdigit(array[i]))
return false;
}
cout << "Your password doesnt contain at least one digit\n";
return true;
}