C++ Language | Creating Password Protection Programs

Saturday 25 May 2013

Nowadays, technology is extremely fast growing. It's not just making our lives more easier but also it let us connect to other people from anywhere around the globe. When we hear the word technology we see it as the gadgets that we use and the World Wide Web (www) that holds any information we need. All of these things are very important because it is handy and the more important it is the more we need to secure it. That is why passwords where invented. Passwords are secret combinations of characters, numbers and even symbols just to protect our confidential information in the digital world.

I decided to make one password program to show you how it looks. Since we are going to make a password program we will be using the string command because users are going to use either characters, numbers or symbols for their passwords. We will also use the string compare statement to compare the inputted password to the original password. Check out the sample codes below.


#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>

using namespace std;

int main()
{
    char password [100];
    int i;
 
    for(i=0;i!=3;i++)

    {
        cout<<"\nENTER PASSWORD: ";
        gets(password);
        int ptr = strcmp ("reymond",password);
     
        if(ptr==0)
        {
            cout<<"\nACCEPTED";
            break;
        }
        else
        {
            cout<<"\nDENIED";
            continue;
        }
    }
    getch();
}

As seen above, the user is allowed only three times to enter his guess. In this matter, the for loop statement will be responsible in counting how many times the user had inputted a guess. If the user's input is evaluated the program will now jump in to the if statement. If the input satisfies the original password then the program will tell you that the password has been accepted and the program will terminate. On the other hand, if the input does not satisfy the original password the program will tell you that it is denied and will ask you two more times. Still if it does not satisfy, the program will automatically terminate. You can check out the sample output below.




Hope you learned something from this lesson. Feel free to leave a comment below. Thanks!


No comments:

Post a Comment

Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!

Related Posts Plugin for WordPress, Blogger...