Thursday, 26 April 2012

"C" programming code that accepts password

| |
The following is a simple code that accept the given password, and masks each entered character as "*" and even accept backspace. This is not for practical usage but for the beginners.


#include<stdio.h>
#include<conio.h>
char pw[25],ch;
int i;
void main()
{
clrscr();
puts(“Enter password”);
while(1)
{
if(i<0)
i=0;
ch=getch();
if(ch==13)
break; /*13 is ASCII value of ENTER*/
if(ch==8) /*ASCII value of BACKSPACE*/
{
putch(‘b’);
putch(NULL);
putch(‘b’);
–i;
continue;
}
pw[i++]=ch;
ch=’*’;
putch(ch);
}
pw[i]=’?;
printf(“nn%s”,pw);
getch();
}

0 comments:

Post a Comment

Social Profiles

Animated Social Gadget - Blogger And Wordpress Tips