Question 13: 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: • 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. 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.
• The password should be at least six characters long.
• The password should contain at least one uppercase and at least one lowercase letter.
/*
Name: Mudassar Ali
Roll: BCSF15M045 [Morning]
Assignment: No# 05
Teacher: Miss Sadia Shahzad
*/
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
cout<<"\t\tThis programme will you ask to enter password!!\n\n";
char pass[20]; // Character array for storing the password.
int Up[26]={0}; // counter for Upper_case letters.
int Lo[26]={0}; // counter for Lower_case letters.
int Nu[26]={0}; // counter for numbers [0-9].
int s1=0,s2=0,s3=0; // sum variable for Up,Lo,Nu strings respectively.
bool flag = false; // Bool function to verify the input values only alphabets and digits only.
cout<<"Enter your password:"; // Getting input.
cin.getline(pass,20);
int len = strlen(pass); // Length of string also find using loop.
if(len>=6) // To valid or invalid the password.
{
for(int i = 0; pass[i]!='\0';i++)// Counter loop
{
if(pass[i]>= 'A' && pass[i]<='Z'||pass[i]>= 'a' && pass[i]<='z'||pass[i]>= '0' && pass[i]<='9') // Password must be between this condition.
{
if(pass[i]>= 'A' && pass[i]<='Z') // counting upper letters.
{
Up[pass[i]-'A']++; // counter for letters
}
else if(pass[i]>= 'a' && pass[i]<='z') // counting lower letters
{
Lo[pass[i]-'a']++; // counter for letters.
}
else if(pass[i]>= '0' && pass[i]<='9') // counter for numbers o - 9
{
Nu[pass[i]-'0']++;
}
}// end of if
else // else part of if
{
flag = true;
}//end of else
}// end of for loop.
if (flag) // true flag.
cout<<"\nWarning!! Your password not contained @,/,1!,$,* etc !!";
for(int x=0;x<26;x++ ) // Summing up the counter strings
{
s1 += Up[x];
s2 += Lo[x];
s3 += Nu[x];
}
// Displaying the following statements
if(s1==0)
cout<<"\nYour password must contain at least ONE UPPER_CASE letter!!\n";
if(s2==0)
cout<<"\nYour password must contain at least ONE LOWER_CASE letter!!\n";
if(s3==0)
cout<<"\nYour password must contain at least ONE DIGIT!!\n";
}// end of first upper if.
else
{
cout<<"\nYou Entered an Invalid Password!!\n";
cout<<"\nYour password must be at least Six digit!!\n";
}
if (!(s1==0 || s2==0 || s3==0)) // to show the password is correct.
cout<<"\n\nYour Password Is Verified."<<endl; // Entered Password.
return 0;
}
No comments: