Question
I need to update this code per these intructions: return a boolean as to whether the password created or reset meets the below criteria and
I need to update this code per these intructions:
return a boolean as to whether the password created or reset meets the below criteria and accepts the password as an argument:
one UpperCase letter
one lowerCase letter
one digit from 0 to 9
one special character or punctuation character
password must be at lease 10 characters long. Count the number of characters in the string for password and return that number.
Validate password must work in every instance.
Here's the code
#include "pch.h" #include
//global variables string FIRST_NAME; string LAST_NAME; string USER_NAME = "17357394739399"; string PASSWORD = "17495739374928";
//function prototypes void greenLight(); void loginUser(); void logoutUser(); void menuSelection(); void registerUser(); void redLight(); void welcomeScreen(); void yellowLight(); void resetPassword();
bool isSpecial(char input_char);
bool validatePassword(string password);
int main()
{ const int ONE = 1,
TWO = 2;
int selection;
welcomeScreen();
cout << "1. Register "; cout << "2. Login "; cout << "Please enter selection: "; cin >> selection;
cin.ignore();
switch (selection) {
case ONE: registerUser();
case TWO: loginUser();
}
return 0;
}
void greenLight() {
cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << "A green light indicates the driver can proceed normally. "; cout << "------------------------------------------------------------------------------------------------------------------------ ";
menuSelection();
}
void loginUser() {
string usernameCheck;
string passwordCheck;
string resetYN;
int attempts = 0;
while (attempts < 3) {
cout << " Please enter username: ";
getline(cin, usernameCheck);
cout << "Please enter password: ";
getline(cin, passwordCheck);
if (usernameCheck == USER_NAME && passwordCheck == PASSWORD) {
cout << " Success! ";
menuSelection();
}
else {
cout << " Please try again. ";
attempts++;
continue;
}
}
if (attempts == 3) {
cout << "Maximum attempts (3) allowed. Do you want to reset password(Y/N)";
getline(cin, resetYN);
if(resetYN=="N")
exit(0);
else
{
resetPassword();
}
}
}
void resetPassword() {
string usernameCheck;
string passwordCheck,passwordNew;
cout << "Please enter current password: ";
getline(cin, passwordCheck);
if (passwordCheck == PASSWORD)
{
cout << "Please choose a new password: ";
getline(cin, passwordNew);
if (validatePassword(passwordNew))
{
cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << " Your password reset successfully. "; cout << "------------------------------------------------------------------------------------------------------------------------ ";
main();
}
else {
cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << " Password reset failed. "; cout << "------------------------------------------------------------------------------------------------------------------------ ";
exit(0);
}
}
}
bool validatePassword(string password)
{
bool flagUpper=true, flagLower=true, flagDigit=true, flagSpecial=true, flagLength=true;
int count;
for (count = 0; count < password.length(); count++)
{
if (isupper(password[count]))
break;
}
if(count==password.length())
{
cout << endl << "No upper case letter used.";
flagUpper = false;
}
for (count = 0; count < password.length(); count++)
{
if (islower(password[count]))
break;
}
if (count == password.length())
{
cout << endl << "No lower case letter used.";
flagLower = false;
}
for (count = 0; count < password.length(); count++)
{
if (isdigit(password[count]))
break;
}
if (count == password.length())
{
cout << endl << "No digit used.";
flagDigit = false;
}
for (count = 0; count < password.length(); count++)
{
if (isSpecial(password[count]))
break;
}
if (count == password.length())
{
cout << endl << "No special character used.";
flagSpecial = false;
}
if (password.length() < 10)
{
cout << endl << "Password is less than 10 characters.";
flagLength = false;
}
if (flagUpper == true && flagLower == true && flagDigit == true && flagSpecial == true && flagLength == true)
return true;
else
return false;
}
bool isSpecial(char input_char)
{
if ((input_char >= 65 && input_char <= 122))
{
return false;
}
else if (input_char >= 48 && input_char <= 57)
{
return false;
}
else
return true;
}
void logoutUser() {
cout << " You will now be logged out . . . ";
exit(0);
}
void menuSelection() {
const int ONE = 1,
TWO = 2,
THREE = 3,
FOUR = 4;
int selectionMenu;
cout << "1. Green Light ";
cout << "2. Yellow Light ";
cout << "3. Red Light ";
cout << "4. Logout ";
cout << "Please enter selection: ";
cin >> selectionMenu;
switch (selectionMenu) {
case ONE:
greenLight();
case TWO:
yellowLight();
case THREE:
redLight();
case FOUR:
logoutUser();
}
}
void registerUser() {
cout << " What is your first name? ";
getline(cin, FIRST_NAME);
cout << "What is your last name? ";
getline(cin, LAST_NAME);
cout << "Please choose a username: ";
getline(cin, USER_NAME);
cout << "Please choose a password: ";
getline(cin, PASSWORD);
int length = PASSWORD.length();
if (length >= 10) {
cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << " You have been registered. Returning to main-menu. "; cout << "------------------------------------------------------------------------------------------------------------------------ ";
main();
}
else {
cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << " Password must be at least 10 characters long. "; cout << "------------------------------------------------------------------------------------------------------------------------ ";
registerUser();
}
}
void redLight() {
cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << "A red light indicates the driver needs to stop as there may be oncoming traffic." << endl; cout << "------------------------------------------------------------------------------------------------------------------------ ";
menuSelection();
}
void welcomeScreen() {
cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << "Welcome to Introduction to Traffic Lights. This program will teach you about the different lights "; cout << "you may see on the road. You will need to register first and then login to view the selections. "; cout << "Once you have logged in you may view info about green lights, yellow lights, and red lights, or you may logout "; cout << "of your account. "; cout << "------------------------------------------------------------------------------------------------------------------------ ";
}
void yellowLight() { cout << "------------------------------------------------------------------------------------------------------------------------ "; cout << "A yellow light indicates the driver should proceed with caution, but should be prepared to stop." << endl; cout << "------------------------------------------------------------------------------------------------------------------------ ";
menuSelection();
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started