https://github.com/Seldaek/hidden-input
隐藏输入
执行此程序允许在交互式CLI应用程序中提示用户输入密码而不在终端中打印密码。
这应该更容易,但遗憾的是,不能用大多数不提供抽象的高级语言来实现它。因此,我没有依赖流行的廉价技巧来使用VBScript来启动提示(由于密码在用户输入密码时显示清楚,因此从未运行良好)我决定使用我在stackoverflow上找到的C ++源代码构建它。积分去guestgulkan 从cplusplus.com,谁他(她)可能会。
用法
获取build / hiddeninput.exe文件到项目中并执行它以接受用户输入。无论用户输入什么,直到换行符将输出回呼叫者但不会显示在终端中。
C ++
hiddeninput.cpp是修改的原始源,因此它可以与VC2008一起编译,从而允许可执行文件从Win XP开始运行良好。
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#define WIN32_LEAN_AND_MEAN
#define NTDDI_VERSION 0x05000000
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));
string s;
getline(cin, s);
cout << s << endl;
return 0;
}
C
hiddeninput.c是我使用祖先conio实用程序的替代版本 。它在功能上并不完全等同于C ++版本,因此我选择不在repo中包含二进制文件。如果你真的对运行编译的C ++代码有不良反应,你可以自己轻松地构建这个代码
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
int main(void) {
int input;
char text[255] = "";
int ptr = 0;
while (++ptr < 255) {
input = _getch();
if (input == 13 || input == 10) {
break;
}
sprintf(text, "%s%c", text, input);
}
printf("%s", text);
return 0;
}