Showing posts with label password security in c++. Show all posts
Showing posts with label password security in c++. Show all posts

Tuesday, February 14, 2017

Password Security in C

Hi guys in this article I would like to share with you a sample program that I wrote that will ask the user to give a password and check if the given password is valid or not. What is good about this program it does not display the password while the user is type it instead it display the asterisk symbol in order to hide the real password to the user. The code is very simple and short I hope you will find my work useful.  I am using Dev C++ as my C++ compiler in this program. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing


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

int main()
{
    char buffer[256] = {0};
    char password[] = "admin";
    char c;
    int pos = 0;

    printf("\n==============================");
    printf("\nPassword Security in C");
    printf("\n==============================");
    printf("\n\n");

     printf("%s", "Give Your Password: ");
    do {
        c = getch();

        if( isprint(c) )
        {
            buffer[ pos++ ] = c;
            printf("%c", '*');
        }
        else if( c == 8 && pos )
        {
            buffer[ pos-- ] = '\0';
            printf("%s", "\b \b");
        }
    } while( c != 13 );

    if( !strcmp(buffer, password) )

    {
        printf("\n\n");
        printf("Password is Accepted.");
        printf("\n\n");
    }
    else
         {
        printf("\n\n");
        printf("Intruder has been detected.");
        printf("\n\n");
    }
        printf("\n\n");
        printf("THANK YOU FOR USING THIS PROGRAM");
        printf("\n\n");
}