没有回显输入密码实现

来源:互联网 发布:mac书法字体下载 编辑:程序博客网 时间:2024/06/06 08:59

InputPassword.exe

注意:

为避免64位操作系统出现错误,做以下设置:

1.MFC的使用:选择“在静态库中使用MFC”

2.配置属性——》C/C++——》常规——》检测64位可移植性问题——》是

#include <stdio.h>#include <string.h>#include <conio.h>#define MAX_PWD_LEN 32void GetPassword(char * pwd){int i = 0;char c;while ((c=getch()) != '\r'){if (i >= MAX_PWD_LEN-1){break;}pwd[i] = c;++i;}}int main(void){char pwd[MAX_PWD_LEN];memset(pwd, 0, MAX_PWD_LEN);GetPassword(pwd);printf_s("%s", pwd);return 0;}


bat脚本:

@echo offecho input the password of sa :set /p sapwd=input the sapwd :echo %sapwd%>>log.txtecho %sapwd%|findstr "^[a-z0-9A-Z_]*$" 1>nul 2>nulif not %errorlevel%==0 (    echo "the sapwd you input is invalid.")for /f "delims=" %%i in ('InputPassword.exe') do (   set sapwd=%%i  )  echo %sapwd% >>log.txtecho %sapwd%|findstr "^[a-z0-9A-Z_]*$" 1>nul 2>nulif not %errorlevel%==0 (    echo "the sapwd you input is invalid.")pause


 

原创粉丝点击