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

Need help with password program part I & II C++. I Appreciate the help. Part I W

ID: 3720598 • Letter: N

Question

Need help with password program part I & II C++. I Appreciate the help.

Part I Write a C++ program to validate a user's password. A user should be able to enter his/her preferred password via keyboard input. Your program checks for specific criteria given below and returns Valid Password or Invalid Password. If the user's preferred password is invalid, it also outputs different reasons. Write separate functions to check the following criteria of the preferred password (each function returns true if it meets a certain criteria): It is at least eight characters long It contains at least one uppercase letter and one lower case letter It contains at least one digit It contains at least one of these four characters: ! @ # $ .

Explanation / Answer

Program is given below:

#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include<string.h>
using namespace std;
bool lengthOk(char []);
bool caseOk(char []);
bool digitOk(char []);
bool charsOk(char []);
void encrypt(char[]);
int r=1;
int main()
{
ofstream myfile;

char s[20],str[20];
bool a,b,c,d;
cin>>s;
a=lengthOk(s);
b=caseOk(s);
c=digitOk(s);
d=charsOk(s);

myfile.open("example.txt");
if(a && b && c && d)
{
cout<<"valid"<<endl;
encrypt(s);
}
myfile<<s<<endl;
myfile.close();
return 0;
}
bool lengthOk(char s[])
{
if(strlen(s)>=8)
return true;
else
{
cout<<"Reason"<<r<<": your password should contain atleast eight characters"<<endl;
r++;
return false;
}
}
bool caseOk(char s[])
{
int i=0,u=0,l=0;
while(s[i]!='')
{
if(s[i]>='a' && s[i]<='z')
l=1;
if(s[i]>='A' && s[i]<='Z')
u=1;
if(l==1 && u==1)
break;
i++;
}
if(l==1 && u==1)
return true;
else
{
cout<<"Reason"<<r<<": your password should contain atleast one uppercase and one lowercase letter"<<endl;
r++;
return false;
}
}
bool digitOk(char s[])
{
int i=0;
while(s[i]!='')
{
if(s[i]>='0' && s[i]<='9')
{
return true;
}
i++;
}
cout<<"Reason"<<r<<": your password should contain atleast one digit"<<endl;
r++;
return false;
}
bool charsOk(char s[])
{
int i=0;
while(s[i]!='')
{
if(s[i]=='!' || s[i]=='@' || s[i]=='#' || s[i]=='$')
return true;
i++;
}
cout<<"Reason"<<r<<": your password should contain atleast one of the four special characters "! @ # $""<<endl;
r++;
return false;
}
void encrypt(char s[])
{
int i=0;
while(s[i]!='')
{
if((s[i]>='a' && s[i]<='z')||(s[i]>='A' && s[i]<='Z') ||(s[i]>='0' && s[i]<='9'))
{
s[i]=s[i]+1;
}
if(s[i]=='!' || s[i]=='@' || s[i]=='#' || s[i]=='$')
{
s[i]=s[i]-1;
}
i++;
}
return ;
}

//If you have any doubt regarding the answer please ask in the comment section

//Please upvote

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