aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
}