Most viewed

28 Nov 2011

C Program To Accept Password [*appearing]




This is a simple login program in C. While accepting password it masks each character using ‘*’ symbol and display the password in the next line after the user hits Enter key. It also accepts backspaces and acts accordingly.


#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]='\0';
printf("\n\n%s",pw);
getch();
}

1 comment:

  1. there is slite mistake when your enter some password and use backspace to remove the earlier one and again write some new password and after you press enter you will able to see both earlier and new password

    ReplyDelete

Confused? Feel free to ask

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.

Note:
Please do not spam Spam comments will be deleted immediately upon my review.

 

Based on your view




You have to try this

This is trending now #