fork download
// Wyatt Carey					    CS1A				 Chapter 10, P. 589, #12
/*******************************************************************************
 * Password Verifier
 * _____________________________________________________________________________
 * This program asks for a password to be created. The password entered must 
 * meet the criteria, otherwise it will dislpay an error message. The program 
 * use character testing for the password to meet it's criteria.
 * _____________________________________________________________________________
 * 
 * INPUTS
 * character testing (cctype functions)
 * OUTPUTS
 *	password or error message.
 ******************************************************************************/
#include <iostream>
#include <cctype>
using namespace std;

// Function Prototypes.
bool passNum(char [], int);

int main() 
{
	// Array settings.
	const int SIZE  = 6;		// Size of the password.
	char password[SIZE];		// To hold the password input.
	
	// Ask for the password to be entered.
	cout << "\tPassword Criteria\n";
	cout << "Enter your password as such: LLlNNN\n";
	cout << "L = uppercase, l = lowercase, N = number\n";
	cin.getline(password, SIZE);
	
	// Password validation
	if (passNum(password, SIZE))
		cout << "Password accepted.\n";
	else
	{
		cout << "\tINCORRECT PASSWORD\n";
		cout << "Enter password as such: LLlNNN";
	}
	return 0;
}

//******************************************************************************
// passNum definition: This function will determine whether testNum parameter  *
// holds a valid input password. The size parameter is the size of the passNum *
// array.																	   *
//******************************************************************************

bool passNum(char testNum[], int size)
{
	int count;		// Loop counter.
	
	// Test the first two characters of the password.
	for (count = 0; count < 2; count++)
	{
		if (!isupper(testNum[count]))
			return false;
	}
	
	// Test the lowercase letter.
	for (count = 0; count <= 1; count++)
	{
		if (!islower(testNum[count]))
			return false;
	}
	
	// Test the last remaining three digits in the password.
	for (count = 0; count < 3; count++)
	{
		if (!isdigit(testNum[count]))
			return false;
	}
	return true;
}
Success #stdin #stdout 0.01s 5284KB
stdin
JFh387
stdout
	Password Criteria
Enter your password as such: LLlNNN
L = uppercase, l = lowercase, N = number
	INCORRECT PASSWORD
Enter password as such: LLlNNN