Tuesday, 30 September 2014

Program to implement security access in c - U can include this function and can provide two level of security

#include <stdio.h>
#include <termios.h>
#include <unistd.h>

int getch(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON | ECHO );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}

int getche(void)
{
    struct termios oldattr, newattr;
    int ch;
    tcgetattr( STDIN_FILENO, &oldattr );
    newattr = oldattr;
    newattr.c_lflag &= ~( ICANON );
    tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
    return ch;
}


void main()
{
char pasword[10],usrname[10], ch;
int i;

//clrscr();

printf("Enter User name: ");
gets(usrname);
printf("Enter the password <any 8 characters>: ");

for(i=0;i<8;i++)
{
ch = getch();
pasword[i] = ch;
ch = '*' ;
printf("%c",ch);
}

pasword[i] = '\0';

/*If you want to know what you have entered as password, you can print it*/
printf("\nYour password is :");

for(i=0;i<8;i++)
{
printf("%c",pasword[i]);
}
printf("\n");
}

No comments:

Post a Comment