Write a program that asks for a password and then verifies that it meets the stated criteria. • If the password meets the criteria, it should state so. • If it doesn’t, the program should display a message telling the user why it failed. • Call your program: MyName-Hwrk10A.cpp . Be sure to put your name as a comment in the code as well as display it in the screen output. • Note, there is no need to give the user a second chance (or more) to type in a different password. The user should simply be told that the password was successful, or why it wasn’t, and then the program can end.

Respuesta :

Missing Details in Question

The password criteria are not stated. For this program, I'll assume the following

  • Password must contain at least 1 capital letter
  • Password must contain at least 1 small letter
  • Password must contain at least 1 digit
  • Password must be at least 8 characters

See Attachment for Source File "MyName-Hwrk10A.cpp"

Answer:

// Comment explains difficult lines

#include<iostream>

#include<cstring>

#include<cctype>

using namespace std;

int main()

{

//Enter your name here

int k,l,m;

/*

Integer variables k,l and m are used to count the number of  

capital letters small letters and digits in the input string (password)

*/

//Initialize them to 0

k=0;l=0;m=0;

int length;

string pass;

cout<<"Password: ";

cin>>pass;

//Calculate length of input string

length = pass.length();

//The following variable is declared to determine if the input string meets criteria

int det = 0;

for(int i = 0;i<pass.length();i++)

{

 if(isupper(pass[i])){ k++;}

 if(islower(pass[i])){ l++;}

 if(isdigit(pass[i])){ m++;}    

}

if(k==0)

{

cout<<"Password doesn't contain capital letters "<<endl;

det++;

}

if(l==0)

{

cout<<"Password doesn't contain small letters "<<endl;

det++;

}

if(m==0)

{

cout<<"Password doesn't contain digit "<<endl;

det++;

}

if(length<8)

{

cout<<"Length of password is less than 8 "<<endl;

det++;

}

if(det == 0)

{

 cout<<"Password meets requirements "<<endl;

}    

 return 0;

}

Ver imagen MrRoyal
Q&A Education