#include "string.h"
#include "stdlib.h"
void password(char *pass)
{ char password[20],inletter=NULL;
int i=0;
clrscr();
gotoxy(17,6);
printf("/n/t/tInput your password:");
while((i<20)&&(inletter!='/r'))
{ inletter=getch(); /*無回顯輸入*/
if(inletter==8)
{ if(i>0)
{password[--i]=NULL;
putchar(8); /*退格鍵*/
putchar(' '); /*以空格代替*/
putchar(8);
}
else putchar(7); /*沒有任何字元的退格,響鈴警告*/
}
else if(inletter!='/r')
{ password[i++]=inletter; /*只要不是退格和回車就接受*/
putchar('*');
}
else
{password[i]=NULL; break; /*密碼輸入完了,記得加個NULL到後面*/
}
}
if(strcmp(password,pass)!=0)
{clrscr();
gotoxy(17,8);
printf("/n/t/tPassword is mistake Tow seconds to exit!");
sleep(2);exit(0);
}
else {printf("/n/t/tPassword is OK! Welcome to come!"); sleep(3);
}
}
void main(void)
{char *pass="lingdlz"; /*初始密碼可以改為其它的*/
password(pass); /*呼叫*/
}