diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-12-05 15:37:44 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-12-05 15:37:44 +0100 |
commit | a77fa92645cd6ef100d3f70473579cf518c8aa9e (patch) | |
tree | 44faa51dc731054e3a26d29a8870670a2cdcc8e3 /src | |
parent | m (diff) | |
download | libpassphrase-a77fa92645cd6ef100d3f70473579cf518c8aa9e.tar.gz libpassphrase-a77fa92645cd6ef100d3f70473579cf518c8aa9e.tar.bz2 libpassphrase-a77fa92645cd6ef100d3f70473579cf518c8aa9e.tar.xz |
add description of strength value
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/passphrase.c | 18 | ||||
-rw-r--r-- | src/passphrase_helper.h | 3 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/passphrase.c b/src/passphrase.c index 2978c80..33c7276 100644 --- a/src/passphrase.c +++ b/src/passphrase.c @@ -43,6 +43,7 @@ #ifdef PASSPHRASE_METER struct passcheck_state { + const char* label; int pipe_rw[2]; pid_t pid; int flags; @@ -93,6 +94,10 @@ static void passcheck_start(struct passcheck_state* state, int flags) if (!command || !*command) command = DEFAULT_PASSPHRASE_METER; + state->label = getenv("LIBPASSPHRASE_STRENGTH_LABEL"); + if (!(state->label) || !*(state->label)) + state->label = PASSPHRASE_TEXT_STRENGTH; + xpipe(state->pipe_rw); xpipe(pipe_rw); xpipe(exec_rw); @@ -230,6 +235,7 @@ static void passcheck_update(struct passcheck_state* state, const char* passphra void* new; char* p; unsigned long long int value; + const char* desc; if (state->flags == 0) return; @@ -301,10 +307,18 @@ static void passcheck_update(struct passcheck_state* state, const char* passphra } strength_ptr = 0; + /* TODO locale */ + if (value == 0) desc = "1;31m" "Well-known common password"; + else if (value <= 150) desc = "31m" "Extremely week"; + else if (value <= 200) desc = "33m" "Week"; + else if (value <= 250) desc = "32m" "Good"; + else if (value <= 350) desc = "1;32m" "Strong"; + else desc = "1;7;32m" "Perfect"; + if (state->flags & PASSPHRASE_READ_SCREEN_FREE) - fprintf(stderr, "\033[s\033[E\033[0K%s%lli\033[u", /*TODO locale*/"Strength: ", value); + fprintf(stderr, "\033[s\033[E\033[0K%s \033[%s\033[m (%lli)\033[u", state->label, desc, value); else - fprintf(stderr, "\033[B\033[s\033[0K%lli\033[u\033[A", value); + fprintf(stderr, "\033[B\033[s\033[0K\033[%s\033[m (%lli)\033[u\033[A", desc, value); fflush(stderr); return; diff --git a/src/passphrase_helper.h b/src/passphrase_helper.h index b8abb3a..e41ca0c 100644 --- a/src/passphrase_helper.h +++ b/src/passphrase_helper.h @@ -45,6 +45,9 @@ #ifndef PASSPHRASE_TEXT_NOT_EMPTY # define PASSPHRASE_TEXT_NOT_EMPTY "(not empty)" #endif +#ifndef PASSPHRASE_TEXT_STRENGTH +# define PASSPHRASE_TEXT_STRENGTH "Strength:" +#endif |