aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-11-22 10:52:55 +0100
committerMattias Andrée <maandree@operamail.com>2013-11-22 10:52:55 +0100
commitc0b27bf6e2350a5eb543966a81d2930275ae8b67 (patch)
tree8c8169f7f3220173c427aabc6a69ea0de7f34428
parentoptionally do not hide the input (diff)
downloadlibpassphrase-c0b27bf6e2350a5eb543966a81d2930275ae8b67.tar.gz
libpassphrase-c0b27bf6e2350a5eb543966a81d2930275ae8b67.tar.bz2
libpassphrase-c0b27bf6e2350a5eb543966a81d2930275ae8b67.tar.xz
add option to print * for each char
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile1
-rw-r--r--src/passphrase.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 5dc054f..7854a06 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ INCLUDE = /include
OPTIONS =
# PASSPHRASE_ECHO: Do not hide the passphrase
+# PASSPHRASE_STAR: Use '*' for each character instead of no echo
OPTIMISE = -Os
CPPFLAGS = $(foreach D, $(OPTIONS), -D'$(D)=1')
diff --git a/src/passphrase.c b/src/passphrase.c
index 43f1431..94922e4 100644
--- a/src/passphrase.c
+++ b/src/passphrase.c
@@ -64,6 +64,18 @@ char* passphrase_read(void)
break;
if (c != 0)
{
+#ifdef PASSPHRASE_STAR
+ if ((c == 8) || (c == 127))
+ {
+ if (len == 0)
+ continue;
+ printf("\033[D \033[D");
+ fflush(stdout);
+ *(rc + --len) = 0;
+ continue;
+ }
+ putchar('*');
+#endif
*(rc + len++) = c;
if (len == size)
if ((rc = realloc(rc, (size <<= 1L) * sizeof(char))) == NULL)
@@ -92,6 +104,9 @@ void passphrase_disable_echo(void)
tcgetattr(STDIN_FILENO, &stty);
saved_stty = stty;
stty.c_lflag &= ~ECHO;
+#ifdef PASSPHRASE_STAR
+ stty.c_lflag &= ~ICANON;
+#endif
tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty);
#endif
}