The objective of this programing assignment is to write a co
The objective of this programing assignment is to write a code to check the strength of a password. Write a C/C++ program named password_ckecker.c, your program will take as input a password (a string) and return a number from 1 to 5 (where 1 is week and 5 is very strong) that represent the strength of the password. Submission: 1. A report describing the criteria used to check the strength of the password. 2. Your code. Note: 1. You have to perform error checking throughout your program. 2. Comment and document all code submitted! 3. Use penguin or clst for your program development and testing. You may do development work on your personal machine but final submissions must compile without errors or warnings and execute without core dumping. 4. Your program will be tested using one of our departmental machines.
Solution
/* Programme code for password strength begins */
 #include <iostream>
 #include <cstring>
 #include <cctype>
 using namespace std;
 int checkPass(char []);                                               //function prototype to check password
 int main()
 {
    char password[100];                                                   //array to hold entered password
    int length;                                                        //hold array length
    cout << \"Please enter password to check strenth : \" << endl;       //Prompt for entering password
    cin >> password;                                                   //read password
    length = strlen(password);                                           //find password length
    if (length < 6)                                                   //check if password length less then 6 display strenth as 1
    {
        cout << \"The password strength is 1\" << endl;
        return 0;
    }
   if (length >=6)                                                   //check if password length greater then 6 ,call testPass function
    {
        int strength= checkPass(password);                               //calling testPass function ,it returns strength of password
       cout << \"The password strength is \" <<strength<< endl;               //dispaly strength of password
    }
return 0;
 }
/*This function will check input password and ensure that the password
 contains a uppercase, lowercase, and digit.*/
int checkPass(char pass[])
 {
        bool aUpper = false,aLower = false,aDigit = false ;           //set flags as false for upper,lower letters,digits
        int len = strlen(pass);                                       //lenth of passeword agian
        for ( int i = 0 ; pass[i] ; ++i )
        {
            if ( isupper(pass[i]) )                                       //check password have uppercase letter then set flag aUpper as true
            aUpper = true ;
            else if ( islower(pass[i]) )                               //check password have LOWER letter then set flag aLower as true
            aLower = true ;
            else if ( isdigit(pass[i]) )                               //check password have digit then set flag aDigit as true
            aDigit = true ;
        }
        if ( aUpper && aLower && aDigit &&len>=8)                   //IF PASSWORD HAVE ALL FLAGS UPPER,LOWER,DIGIT AND LENGTH >8 THEN RETURN 5
            return 5;
        else if (aUpper && aLower && aDigit)                       //IF PASSWORD HAVE ALL FLAGS UPPER,LOWER,DIGIT THEN RETURN 4
       
            return 4 ;
        else if (( aUpper && aLower)||( aUpper && aDigit)||( aLower && aDigit))       //IF PASSWORD HAVE ATLEAST TWO FLAGS UPPER,LOWER,DIGIT THEN RETURN 3
            return 3 ;
        else                                                        //IF PASSWORD HAVE ATLEAST ONE FLAG UPPER|LOWER|DIGIT THEN RETURN 2
            return 2;
                                                           
 }
 /* Programme code for password strength Ends */
Note :
IF PASSWORD HAVE ALL FLAGS UPPER,LOWER,DIGIT AND LENGTH >8 THEN RETURN 5
 IF PASSWORD HAVE ALL FLAGS UPPER,LOWER,DIGIT THEN RETURN 4
 IF PASSWORD HAVE ATLEAST TWO FLAGS UPPER,LOWER,DIGIT THEN RETURN 3
 IF PASSWORD HAVE ATLEAST ONE FLAG UPPER|LOWER|DIGIT THEN RETURN 2
 IF PASSWORD lessthan 6 THEN RETURNs 1
Output 1 :
Please enter password to check strenth :
 skd
 The password strength is 1
Output 2 :
Please enter password to check strenth :
 Ashok4jjj
 The password strength is 5


