InputPassword.exe
注意:
为避免64位操作系统出现错误,做以下设置:
1.MFC的使用:选择“在静态库中使用MFC”
2.配置属性——》C/C++——》常规——》检测64位可移植性问题——》是
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAX_PWD_LEN 32
void 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 off
echo input the password of sa :
set /p sapwd=input the sapwd :
echo %sapwd%>>log.txt
echo %sapwd%|findstr "^[a-z0-9A-Z_]*$" 1>nul 2>nul
if not %errorlevel%==0 (
echo "the sapwd you input is invalid."
)
for /f "delims=" %%i in ('InputPassword.exe') do (
set sapwd=%%i
)
echo %sapwd% >>log.txt
echo %sapwd%|findstr "^[a-z0-9A-Z_]*$" 1>nul 2>nul
if not %errorlevel%==0 (
echo "the sapwd you input is invalid."
)
pause