Check password string computation and loop websites impose c
Solution
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
using namespace std;
// function declaration of password validation
bool isPassword(char[]);
int main()
{
//input from the user
char password[100];
cout<<\"Enter password: \"<<endl;
cin>>password;
if(isPassword(password)){
cout<<\"Valid Password\";
}else{
cout<<\"Invalid Password\";
}
return 0;
}
// method to return whether is valid or invalid assword. Returns true or false;
bool isPassword(char password[]){
bool ispassword=true;
// length of the password
int len=strlen(password);
// if the length is greater than 8
if(len>8){
int digitCount=0;// to count the number of digit
for(int i=0;i<len;i++){
// if the current char is alphanumberic
if(!isalnum(password[i])){
return false;
}
// if the current char is isDigit
if(isdigit(password[i])){
digitCount++;
}
}
//check if digitCount is less than 2 than return false
if(digitCount<2){
return false;
}
}
// if the length is less than 8 chars
else{
return false;
}
return true;
}
---------------------output----------------------
Hello1234
Valid Password
HelloWorld1
Invalid Password
HelloWord12 Valid Password
Hello Invalid Password
--------------output ends------------------
Note: feel free to ask any doubts. God bless you!

