From 209c4a37c0dd861058c916cb47b62144e74a7b16 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sun, 22 Feb 2009 16:38:43 +0000 Subject: [PATCH] #44 hide password input --- src/common.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index ac56486..f231c7c 100644 --- a/src/common.c +++ b/src/common.c @@ -28,7 +28,8 @@ #include #ifdef WINDOWS32 -#include +#include +#include #else #include #ifdef DARWIN @@ -183,11 +184,26 @@ read_password(char *buf, size_t len) tp.c_lflag &= (~ECHO); tcsetattr(0, TCSANOW, &tp); +#else + int i; #endif printf("Enter password: "); fflush(stdout); +#ifndef WINDOWS32 scanf("%79s", pwd); +#else + for (i = 0; i < sizeof(pwd); i++) { + pwd[i] = getch(); + if (pwd[i] == '\r' || pwd[i] == '\n') { + pwd[i] = 0; + break; + } else if (pwd[i] == '\b') { + i--; /* Remove the \b char */ + if (i >=0) i--; /* If not first char, remove one more */ + } + } +#endif printf("\n"); #ifndef WINDOWS32