Write before:

Have you ever feel amazed when you settle to think about the principles when you entering your password?

I haver always been curious about that.

So lets' uncover the mystery now!


#include <stdio.h>
#include <conio.h>
#define MAX_PSD_LEN 20

char PassWord[MAX_PSD_LEN],*p=PassWord,ch;
int count=0;
 main()
{
    ch=getch();
    while(ch!=13&&count<MAX_PSD_LEN-1)       /*当按下回车键或密码长度达到19,则退出循环*/
    {
        if(ch==8)                       /*如果按下的是向前删除键,则...*/
        {
            if(count)              /*如果密码串中字符数大于零,则向前删除一个字符*/
            {
                p--;
                count--;
                printf("\b ");/*光标回退一格,将星号(*)改为空格*/
                printf("\b"); /*光标重新回退一格*/
            }
        }
        else if((ch<='Z'&&ch>='A')||(ch<='z'&&ch>='a')||(ch<='9'&&ch>='0'))
                                                  /*如果输入的是密码的有效字符*/
        {
            printf("*");          /*输出一个星号*/
            count++;
            *p=ch;                /*记录密码内容*/
            p++;
        }
        ch=getch();                    /*等待输入下一个字符*/
    }
    PassWord[count]=0;
    printf("\nThe Password you input is:\n");
    printf("%s\n",PassWord);
}