Make Windows client read password without echo again
Commit 8c3b8d10
replaced the getpass() for Windows by a generic
ersatz_getpass(). This lost the "switch off echo" feature, with the
excuse that it doesn't work for me (MinGW & Wine). Turns out it works
under real Windows. Restore the feature.
This commit is contained in:
parent
b1e6004148
commit
eb1041f130
1 changed files with 12 additions and 1 deletions
|
@ -52,11 +52,22 @@ ersatz_getpass(char *prompt)
|
|||
static char buf[128];
|
||||
char *p;
|
||||
size_t len;
|
||||
#ifdef _WIN32
|
||||
DWORD mode;
|
||||
HANDLE input_handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
printf("Note: your input is echoed to the screen\n");
|
||||
if (GetConsoleMode(input_handle, &mode))
|
||||
SetConsoleMode(input_handle, mode & ~ENABLE_ECHO_INPUT);
|
||||
else
|
||||
#endif
|
||||
printf("Note: your input is echoed to the screen\n");
|
||||
printf("Your name? ");
|
||||
fflush(stdout);
|
||||
p = fgets(buf, sizeof(buf), stdin);
|
||||
#ifdef _WIN32
|
||||
if (GetConsoleMode(input_handle, &mode))
|
||||
SetConsoleMode(input_handle, mode | ENABLE_ECHO_INPUT);
|
||||
#endif
|
||||
if (!p)
|
||||
return NULL;
|
||||
len = strlen(p);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue