#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
//function prototypes
void displayRules();
bool validatePasswd(char *passwd);
int main()
{
char newpasswd[25];
bool OK = false;
while (!OK)
{
cout << "Enter a valid password. To see the password rules, type ? and press enter."<< endl;
cin >> newpasswd;
//check whether the user entered a ?
// FILL IN MISSING CODE TO DISPLAY RULES IF THE USER ENTERED a ?
else {
OK = validatePasswd(newpasswd);
if (OK)
cout << "Your password has been accepted. "<< endl;
}
} // end while
return 0;
} // end main
void displayRules()
{
// FILL IN THE MISSING CODE TO DISPLAY THE RULES
return;
}
bool validatePasswd(char *passwd)
{
bool OK=false;
//Check length
if (//FILL IN THE CONDITION)
{
cout << "Length must be at least 8" << endl;
return false;
}
//Check for alpha character
//FILL IN CODE HERE. Note: The next 3 tests are very similar to one another.
//Check for numeric character
//FILL IN CODE HERE
//Check for special character
//FILL IN CODE HERE
// Check that the password does not begin with ? or !
if (passwd[0]=='?' || passwd[0]=='!') return false;
// Check that the first 3 characters are not equivalent
//FILL IN CODE HERE
return true;
}