From 6e167c65df1da839c63b12dee04d86d2bf6708d9 Mon Sep 17 00:00:00 2001 From: Damien Stuart Date: Sun, 14 Jun 2009 16:38:17 +0000 Subject: [PATCH] Added handling of Backspace and Ctrl-U in the Win32 handling of get_passswd. git-svn-id: file:///home/mbr/svn/fwknop/trunk@105 510a4753-2344-4c79-9c09-4d669213fbeb --- src/getpasswd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/getpasswd.c b/src/getpasswd.c index b0b49fd6..5f3c4fd1 100644 --- a/src/getpasswd.c +++ b/src/getpasswd.c @@ -81,11 +81,32 @@ getpasswd(const char *prompt) #ifdef WIN32 _cputs(prompt); while((c = _getch()) != '\r') + { + /* Handle a backspace without backing up too far. + */ + if(c == '\b') + { + if(ptr != pwbuf) + *ptr--; + + continue; + } + + /* Handle a Ctrl-U to clear the password entry and start over + * (like it works under Unix). + */ + if(c == 0x15) + { + ptr = pwbuf; + continue; + } #else while((c = getc(fp)) != EOF && c != '\n') + { #endif if(ptr < &pwbuf[MAX_PASS_LEN]) *ptr++ = c; + } /* Null terminate the password. */