C Imagine you are developing a software package that require
C++
Imagine you are developing a software package that requires users to enter their own passwords. Your software requires that users’ passwords meet the following criteria:
a) The password should be at least six characters long.
b) The password should contain at least one uppercase and at least one lowercase letter.
c) The password should have at least one digit.
Write a program that asks for a password and then verifies that it meets the stated criteria. If it doesn’t, the program should display a message telling the user why (in specific).
Solution
Here is the C++ Code for the above scenario:
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main()
{
const int LENGTH = 101;
char List[LENGTH];
int Upper, Lower, Digit;
cout << \"Create your password\ \"
<< \"passwords must meet the following criteria:\ \"
<< \" • The password should be at least six characters long.\ \"
<< \" • The password should contain at least one uppercase\ \"
<< \" and at least one lowercase letter.\ \"
<< \" • The password should have at least one digit.\ \";
do
{
Upper = Lower = Digit = 0;
cout << \"Enter password: \";
cin.getline(List, LENGTH);
for (int i = 0; i < strlen(List); i++)
{
if (isupper(List[i]))
Upper++;
if (islower(List[i]))
Lower++;
if(isdigit(List[i]))
Digit++;
}
if (strlen(List) < 6)
cout << \"password is not at least six characters long.\ \";
if (Upper == 0)
cout << \"password does not contain at least one uppercase letter.\ \";
if (Lower == 0)
cout << \"password does not contain at least one lowercase letter.\ \";
if (Digit == 0)
cout << \"password does not have at least one digit.\ \";
}
while (Upper == 0 || Lower == 0 || Digit == 0 || strlen(List) < 6);
cout << \"Password verified. Your password is: \" << List << endl;
return 0;
}

