Password Validator example in C++ Programming Language

Avatar

 BY TEJAS




What is a Password?
A secret word which gives access to somewhere.

We all know strong passwords contain "Alphabets, Digits, and Special Symbols". So, we see in some websites or apps there is mandatory for passwords like this Alphabets, Digits, at least one capital letter, and at least one Special symbol.



In that case, you can not write your name as Password, similarly your pet's name as a password, your mobile number as password. This type of passwords is very weak it can be easily hacked.
Accepted passwords in password validators are very strong easily does not hacked. Our carelessness is responsible for 50% of hacking and cracking.


Also Check:-
  • Addition of two numbers in C++




  • This type of passwords form is mainly like this [email protected]. As you see in this demo password we use alphabets, Digits, at least one capital letter, and at least one special symbol, Minimum length of password is 8 characters. [email protected] is also satisfied with the condition of password validator.

    We all know how much password validator is essential for our security.
    So, hence we use password validators for getting the user safe and secure. Password validator is nothing just that see the password and check that all conditions which we see in above paragraph and that conditions check in your password and gives you suggestion.

    Come back to our Password Validator example in C++.
    In this example, we mainly use If....else statements (if this happens to do this) like that and also we use boolean operator for this program (boolean is true or false, yes or no) like that.

    Also Check:-
  • Face on dice example in java programming

  • How the program works?
    When you run the program, it says to enter the password we have to type our password and enter enter it starts compiling and executing and do all the process in which C++ runs the program. After you entered your password, it checks all conditions if your password satisfied that conditions it shows "Valid Password" and it does not then you get like this "Password doesn't have any digits"


    So this is our password validator program in C++

    Password Validator

    In below video shows program


    below here is a C++ code program and output of C++ program.

    main.cpp :-
        
    
        #include <iostream>
        #include <string.h>
        using namespace std;
        int main() {
        bool y;
        y=false;
        typedef char str[15];
        str a;
        cin.getline(a,15);
        int l =strlen(a);
        if(l>=5 && l<=10)
        {   
        int c=0,n=0;
        for(int i=0;i='0' && a[i]<='9')
        {
        n++;
        continue;
        }
        y=((a[i]>='a' && a[i]<='z') || (a[i]>='A' && a[i]<='Z'));
        if (y==false)
        {
        c++;
        }
        if (a[i]==' ')
        {
        c=0;
        n=0;
        break;}    
        }
        if(n>0 && c>0)
        cout<<"Password is valid!";
        else
        {
        if (n==0)
        cout<<"Password doesn't have any digits!";
        else
        cout<<"password doesn't have any special character!";
        }
        }
        else
        cout<<"Password too short/long!";
            return 0;
        }
            
        
    


    output :-
        
           
            [email protected]
            Password is valid!
    
            Process returned 0 (0x0)   execution time : 12.841 s
            Press any key to continue.
    
        
      
        
            #include <iostream>
                #include <string.h>
                using namespace std;
                int main() {
                bool y;
                y=false;
                typedef char str[15];
                str a;
                cin.getline(a,15);
                int l =strlen(a);
                if(l>=5 && l<=10)
                {   
                int c=0,n=0;
                for(int i=0;i='0' && a[i]<='9')
                {
                n++;
                continue;
                }
                y=((a[i]>='a' && a[i]<='z') || (a[i]>='A' && a[i]<='Z'));
                if (y==false)
                {
                c++;
                }
                if (a[i]==' ')
                {
                c=0;
                n=0;
                break;}    
                }
                if(n>0 && c>0)
                cout<<"Password is valid!";
                else
                {
                if (n==0)
                cout<<"Password doesn't have any digits!";
                else
                cout<<"password doesn't have any special character!";
                }
                }
                else
                cout<<"Password too short/long!";
                    return 0;
                }
            
        
    


    output :-
        
           
            [email protected]
            Password is valid!
    
            Process returned 0 (0x0)   execution time : 12.841 s
            Press any key to continue.