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

Write a program C++ that will validate the password a user enters. The program f

ID: 3676179 • Letter: W

Question

Write a program C++ that will validate the password a user enters. The program first gets the persons full name as a string and then his username (also string), followed by the password, then validates the password.

A valid password must:

contain a minimum of 8 chars

Must meet 3/4 following criteria:

at least one uppercase letter

at least one lowercase letter

at least one number

at least one non-alphabetic character/symbol ($!#%etc.)

the password cannot contain:

the person's username

his first or last name

his initials

If password is ok, display a message accordingly. If not, make the user re-input as many times as necessary.

Explanation / Answer

Please find the required program below:

#include<iostream>
#include<cctype>
#include <stdio.h>
#include <string.h>
using namespace std;
//function prototypes
bool verifyPass(char [],string,string);

int main()
{
  
string name,username;
char password[10];
  
cout << "Enter Name, username and password: ";
getline(cin,name);
getline(cin,username);
cin.getline(password, 10);
  
if(verifyPass(password,name,username))
cout << "That is a valid password ";
else
cout << "That is an invalid password ";
system("pause");
return 0;   
}
bool verifyPass(char pw[],string name, string username)
{
int count=4;
int length;
length = strlen(pw);
string p = string(pw);
  
if (p.find(name) == std::string::npos) {
return false;
}
if (p.find(username) == std::string::npos) {
return false;
}

if(length >= 8)
{
for (int count = 0; count < length; count++)
{
while (!islower(pw[count]))
count--;
}
  
for (int count = 0; count < length; count++)
{
while (!isdigit(pw[count]))
count--;
}
for (int count = 0; count < length; count++)
{
while (!isupper(pw[count]))
count--;
}
}
else {
count--;
}
  
if(count>=3)
return true;
else
return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote