zoukankan      html  css  js  c++  java
  • 一个只能用在Win下的密码验证函数(显示星号,可删除)

    以前做小程序时图好玩在网上找的代码。输入的密码会以星号显示出来,并且输入错了可以删除。因为用了专有库函数,所以只能在Windows平台使用,少用为好,不过可能还有点用。嗯…就这样了

    #include <stdio.h>
     
    #include <string.h>
     
    #include <conio.h>
     
    #define  MAX_PASSLEN 128           //定义密码长度
     
    char tpass[20]="admin";
     
    void GetPassword(char *szFinalPass)
     
    {
     
        char chValue,szPassword[MAX_PASSLEN];
     
        int iCounter = 0;                //定义计数器
     
        while ( 1 )
     
        {
     
            if( ( chValue = getch() ) != '
    ' )                //如果输入的不是回车
     
            {
     
                if( chValue != '' )                                //如果输入的不是退格
     
                {
     
                    if ( iCounter < MAX_PASSLEN )         //如果长度并未超过密码的最大长度
     
                    {
     
                        szPassword[iCounter] = chValue;
     
                        putchar( '*' );                               //在屏幕上显示星号
     
                        iCounter ++;
     
                    }
     
                    else
     
                    {
     
                        putchar( '7' );                             //如果密码已经超过最大长度,则响铃报警
     
                    }
     
                }
     
                else
     
                {
     
                    if( iCounter != 0 )                                  //如果按了退格,并且当前不是第一个字符
     
                    {
     
                        iCounter --;
     
                        printf( " " );                           //注意两个之间是有个空格的,含义是先退格,
     
                        //然后打印空白字符将之前的字符覆盖掉,然后再退格使光标退回
     
                    }
     
                }
     
            }
     
            else
     
            {
     
                szPassword[iCounter] = 0;                         //密码输入结束时将末尾以结尾!
     
                break;
     
            }
     
        }
     
        strcpy( szFinalPass ,szPassword );                              //最终将密码复制出来
     
    }
     
    int main()
     
    {
     
        char szPassword[128];
     
        GetPassword(szPassword);
     
        if(strcmp(szPassword,tpass)==0)
            printf("
    输入的密码是:%s
    ",szPassword);
     
        else
            printf("
    密码错误
    ");
    }
  • 相关阅读:
    python3中的文件操作
    python3网络爬虫实现有道词典翻译功能
    C++11 thread condition_variable mutex 综合使用
    goland scope pattern 设置
    Go 1.11 Module 介绍
    hustOJ 添加 golang 支持
    docker 搭建 hustoj
    最长重复字符串题解 golang
    golang 结构体中的匿名接口
    使用aliyun cli工具快速创建云主机
  • 原文地址:https://www.cnblogs.com/ishell/p/4240169.html
Copyright © 2011-2022 走看看