Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ We take for granted that all of our users know what constitutes a good pa

ID: 3824671 • Letter: I

Question

In C++

We take for granted that all of our users know what constitutes a good password - and every year we have more and more proof that it simply isn't the case (2013's (Links to an external site.)Links to an external site. offenders, 2014's (Links to an external site.)Links to an external site. offenders, 2015's (Links to an external site.)Links to an external site.offenders). Today you will create a simple program that takes in a user's password, validates it for length and difficulty, and if it checks out set it to their password moving forward.

Here are some things to consider (from ISU (Links to an external site.)Links to an external site.):

Following these simple rules will add complexity to your password, thereby making it much harder to crack:

Use a password that is at least eight (8) characters in length (and preferably even longer than eight characters).

Use uppercase and lowercase letters. (Security researchers have found starting a password with a lowercase letter actually creates more work for password cracking software)

Use numbers.

Use symbols such as $, %, &, etc.

Adhering to those rules, your program will:

Take in a user's new password (2.5 POINTS)

Make sure that the user entered the password they thought they entered (15 POINTS)

Check it for proper length (5 POINTS)

If too short prompt them to enter another (5 POINTS)

Check that password for numbers, and special characters (20 POINTS)HINTS!

use booleans to check for special characters and numbers (2.5 POINTS)

copy the string to an array to use so you don't accidentally change the entered string (see bottom code snippet) (10 POINTS)

use the number row only for special characters (10 POINTS)

Use named constants to maintain size of your arrays and looping mechanisms (5 POINTS)

Use good design principles to allow the user proper interactions with your program and lead them to desired outcomes (10 points)

while (enterPWD[i] != '' && i < namedConstant)
     {
        password[i] = enterPWD[i];
        i++;

     }
       password[i] = '';

Explanation / Answer


#include <iostream>
#include <cctype>
#include <cstring>

using namespace std;

enum PWSIZE
{
PASSWORD_SIZE = 20
};


int testNum(char []);

int main()
{
char password[PASSWORD_SIZE];
int length;

length = strlen(password);
while(1)
{
  
do{
cout<< "Please enter a password with at least 6 characters. ";
cout << "Enter your password: ";
cin.getline(password, PASSWORD_SIZE);
length = strlen(password);
}while(length < 6);

  
if(testNum(password))
continue;
  

break;
}
return 0;
}

int testNum(char pswd[])
{
int count;
bool upper_flag = 0, lower_flag = 0, digit_flag = 0;
for (count = 0; count<strlen(pswd); count++)
{

if (isupper(pswd[count]))
upper_flag = 1;
else if (islower(pswd[count]))
lower_flag = 1;
else if (isdigit(pswd[count]))
digit_flag = 1;
}
if(!upper_flag)
{
cout << "The password does not contain an uppercase letter. ";
}

if(!lower_flag)
{
cout << "The password does not contain a lowercase letter. ";
}
if(!digit_flag)
{
cout << "The password does not contain a digit. ";
}
if(upper_flag && lower_flag && digit_flag)
return 0; //if all pass
else
return 1;
}

return 0;
}