PA 4 Password Game
Please write a C++ program to check a password to see whether it is really secure.This program is like a password game.If the password is not secure, your program must report all its security violations.Please see the following test case #1 to design your application program.You must stop your program when the password from the user is quit.In other words, quit cannot be a password in this game.
You must write 7 functions to check the following 7 security rules for any given password.
Rule 1: Length invalid The length of the password must be 8 to 12 only.
Rule 2: No Space The password must not contain any space or blank character.
Rule 3: At least 2 digits The password must contain at least 2 digits.
Rule 4: At least 1 upper-case letter The password must contain at least one upper-case letter.
Rule 5: At least 1 lower-case letter The password must contain at least one lower-case letter.
Rule 6: At least 1 special character The password must contain at least one special character, which can be one of the following 7 choices: $, #, @, &, *, ?, or !.
Rule 7: No special numbers The password must not contain any of the following 4 numbers: 2019, 2018, 2017, or 2016.
The following is a sample standard test, which must be your test case #1.You must also do test case #2 and test case #3 with different set of input data.Each test case must test at least 5 passwords with 2 secure and 3 non-secure. All those 7 violations must appear in those 3 non-secure passwords.
Welcome to the PASSWORD game designed by Dr. Simon Lin!
Please enter a password:0 0 7
The password 0 0 7 violates the following rule(s):
Rule 1: Length invalid The length of the password must be 8 to 12 only.
Rule 2: No Space The password must not contain any space or blank character.
Rule 4: At least 1 upper-case letter The password must contain at least one upper-case letter.
Rule 5: At least 1 lower-case letter The password must contain at least one lower-case letter.
Rule 6: At least 1 special character The password must contain at least one special character, which can be one of the following 7 choices: $, #, @, &, *, ?, or !.
Please enter a password:$007SLin!
Your password $007SLin! is very secure! Congratulations!
Please enter a password:#1SimonLin
The password #1SimonLin violates the following rule(s):
Rule 3: At least 2 digits The password must contain at least 2 digits.
Please enter a password:SLin2019@
The password SLin2016@ violates the following rule(s):
Rule 7: No special numbers The password must not contain any of the following 4 numbers: 2019, 2018, 2017, or 2016.
Please enter a password:$2020LinWins
Your password $2020LinWins is very secure! Congratulations!
Please enter a password:quit
Your password quit is to quit the game.
Thank you for playing the PASSWORD game designed by Dr. Simon Lin!
==========================================================================.
The following is a sample code with some pseudo-code for this Password Game program:
#include pch.h
#include
#include
using namespace std;// Access cout, endl, cin
string pw; // global pw for the password
bool r1, r2, r3, r4, r5, r6, r7; // global 7 boolean flags for violations
void s1(); void s2(); void s3(); void s4();
void s5(); void s6(); void s7();// 7 prototypes
int main()
{ // begin of main
cout << “Welcome to the PASSWORD game designed by Dr. Simon Lin!” << endl;cout << “Please enter a password:” << endl;getline(cin, pw); // pw may have blanks anywherecout << “Your password “” << pw << “” ” ;while (pw != “quit”){ //begin of while loops1(); s2(); s3(); s4();s5(); s6(); s7();// call to check all 7 rules for satisfactionif (r1 && r2 && r3 && r4 && r5 && r6 && r7) // all 7 rules satisfied cout << “is very secure! Congratulations!” << endl ;else // insecure password{ // print the insecure password message with all rules violated cout << “violates the following rule(s):” << endl ;if (!r1) cout << “Rule 1: Length invalid The length of the password must —if (!r2) cout << “Rule 2: No Space The password must not contain any space —if (!r3) cout << “Rule 3: At least 2 digits The password must — if (!r4) cout << “Rule 4: At least 1 upper-case letter The password must —if (!r5) cout << “Rule 5: At least 1 lower-case letter The password must —if (!r6) cout << “Rule 6: At least 1 special character The password must –if (!r7) cout << “Rule 7: No special numbers The password must not contain — } // print all the violated rules in detailcout << “Please enter a password:” << endl;getline(cin, pw); // pw may have blanks anywherecout << “Your password “” << pw << “” “;} // end of while loopcout << “is to quit the game.” << endl;cout << “Thank you for playing the PASSWORD game designed by Dr. Simon Lin!”;return 0 ; // normally done now} // end of main =======================================================You may use the following idea to check upper/lower case characters and digits string upperChars = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;string lowerChars = “abcdefghijklmnopqrstuvwxyz”;string specialChars = “$#@&*?!”;Some other helpful programming techniques/methods/functions for strings are as follows:(pw.find(“2019″) == string::npos)will return true if pw does not contain 2019. (pw.find(” “) == string::npos)will return true if pw does not contain any blank character.pw.length( ) will return the length of the string pw. You may need to use some string methods such as at( ), length( ), or find( ). A special technique to check for the Rule 3 (at least 2 digits in password) is as follows: void s3() // to check for security rule 3{ // begin of s3( )char c ;int countDigits ;string digits = “0123456789”;countDigits = 0;r3 = false;for (int i = 0; i < pw.length(); i++){c = pw.at(i);if (digits.find(c) != string::npos)countDigits++;}if (countDigits >= 2)
r3 = true; // for Rule 3 checking: at least 2 digits
} // end of s3( )
======================================================================.
How to submit your Lab or Project Assignment (PA)?
(1) Each program must be well documented with block comments and proper line comments.
The beginning of each program must have a block comment to show its author, date, and purpose.
The following is an example of block comments:
// Author:You must use your full name here!
// Date: You must put todays date here!
// Purpose: . . . You must show the purpose of this program here!
(2) You must submit to Canvas the following 2 items as attachments:
(a) Your source program (for example, CS243-PA4.cpp ), and
(b) Your WORD document (for example, CS243-PA4-report .docx ) containing the listing of
your C++ program, and the output of 3 test runs of your program (as shown below).
=========================================================================.
// Please delete everything above this line to make this your Word document to be submitted.
PA 4Report My Name: ________________
The following is my C++ source program:
// Please copy your source program into here from your Visual Studio window.The code must be colored.
// You must not copy source program from your PA4.cpp file since the code over there is not colored at all.
The following is the output of3 test runs of my program:
// One way to copy the console output is press Ctrl+Alt+PrtScn.To paste it is to press Ctrl+v.
// Please copy your console output and paste into here:
Reviews
There are no reviews yet.