implemented hidden password input for windows by using conio

Thu, 08 Oct 2015 14:25:53 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 08 Oct 2015 14:25:53 +0200
changeset 153
272173064319
parent 152
ff854d3df20c
child 154
3cfb4670d9e6

implemented hidden password input for windows by using conio

libidav/utils.c file | annotate | diff | comparison | revisions
mingw.mk file | annotate | diff | comparison | revisions
--- a/libidav/utils.c	Thu Oct 08 12:58:49 2015 +0200
+++ b/libidav/utils.c	Thu Oct 08 14:25:53 2015 +0200
@@ -37,8 +37,12 @@
 #include <libxml/tree.h>
 #include <curl/curl.h>
 
-#ifndef _WIN32
+#ifdef _WIN32
+#include <conio.h>
+#define getpasswordchar() getch()
+#else
 #include <termios.h>
+#define getpasswordchar() getchar()
 #endif
 
 #include <openssl/sha.h>
@@ -447,10 +451,8 @@
     fprintf(stderr, "%s", prompt);
     fflush(stderr);
     
+#ifndef _WIN32
     // hide terminal input
-#ifdef _WIN32
-    // TODO
-#else
     struct termios oflags, nflags;
     tcgetattr(fileno(stdin), &oflags);
     nflags = oflags;
@@ -464,18 +466,17 @@
     // read password input
     UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
     int c = 0;
-    while((c = getchar()) != EOF) {
-        if(c == '\n') {
+    while((c = getpasswordchar()) != EOF) {
+        if(c == '\n' || c == '\r') {
             break;
         }
         ucx_buffer_putc(buf, c);
     }
     ucx_buffer_putc(buf, 0);
+    fflush(stdin);
     
+#ifndef _WIN32
     // restore terminal settings
-#ifdef _WIN32
-    // TODO
-#else
     if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
         perror("tcsetattr");
     }
--- a/mingw.mk	Thu Oct 08 12:58:49 2015 +0200
+++ b/mingw.mk	Thu Oct 08 14:25:53 2015 +0200
@@ -31,7 +31,7 @@
 AR = ar
 RM = rm
 
-CFLAGS  = -std=gnu99 -c -O2 -m64
+CFLAGS  = -std=gnu99 -c -O2
 COFLAGS = -o
 LDFLAGS = 
 LOFLAGS = -o
@@ -43,5 +43,5 @@
 APP_EXT = .exe
 
 DAV_CFLAGS = -I /mingw/include/libxml2
-DAV_LDFLAGS = -m64 -lcurl  -lxml2 -lssl -lcrypto -lws2_32 -lgdi32 -lregex
+DAV_LDFLAGS = -lcurl  -lxml2 -lssl -lcrypto -lws2_32 -lgdi32 -lregex
 

mercurial