Tuesday, August 16, 2011

Comparing the password

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
char ch;
char pw[100];
char pswd[]="password";
int i=0;
clrscr();
printf("Enter the password:\n");
ch=getch();
while(ch!=13)
{
if(ch==8)
{
printf("\b");
putch(NULL);
printf("\b");
pw[i]='\0';
--i;
}
else
{
printf("%c",ch);
putch('\b');
printf("*");
pw[i++]=ch;
}
ch=getch();
}
pw[i]='\0';
printf("\npassword is:%s",pw);
if(strcmp(pswd,pw)==0)
{
printf("\n password matched");
}
else
{
printf("\n password in wrong");
}
getch();
}