Check password string computation and loop websites impose c

(Check password, string computation, and loop) websites impose certain rules for Some passwords. Suppose the password rules are as follows: e Apassword must have at least eight characters. A password must consist of only letters and digits A password must contain at least two digits. rite a program that prompts the user to enter a password and display \"valid Password\" if the rules are followed or \"Invalid Password\" otherwise

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!

 (Check password, string computation, and loop) websites impose certain rules for Some passwords. Suppose the password rules are as follows: e Apassword must ha
 (Check password, string computation, and loop) websites impose certain rules for Some passwords. Suppose the password rules are as follows: e Apassword must ha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site