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 | |
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 '')
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | info/libpassphrase.texinfo | 23 | ||||
-rw-r--r-- | src/passphrase.c | 18 | ||||
-rw-r--r-- | src/passphrase_helper.h | 3 |
4 files changed, 40 insertions, 9 deletions
@@ -50,8 +50,11 @@ PASSPHRASE_STAR_CHAR = * PASSPHRASE_TEXT_EMPTY = (empty) # Text to use instead of "(not empty)" PASSPHRASE_TEXT_NOT_EMPTY = (not empty) +# Text to use instead of "Strength:" +PASSPHRASE_TEXT_STRENGTH = Strength: -QUOTED_OPTIONS = PASSPHRASE_STAR_CHAR PASSPHRASE_TEXT_EMPTY PASSPHRASE_TEXT_NOT_EMPTY +QUOTED_OPTIONS = PASSPHRASE_STAR_CHAR PASSPHRASE_TEXT_EMPTY PASSPHRASE_TEXT_NOT_EMPTY \ + PASSPHRASE_TEXT_STRENGTH # Optimisation settings for C code compilation diff --git a/info/libpassphrase.texinfo b/info/libpassphrase.texinfo index 475b50f..8b76067 100644 --- a/info/libpassphrase.texinfo +++ b/info/libpassphrase.texinfo @@ -165,6 +165,10 @@ the the screen. This is only used if combined with will create make a line below the new current line and use that line to draw the passphrase strength meter if such capability is available. + +The label for the passphrase strength meter can +be modified by setting the environment variable +@env{LIBPASSPHRASE_STRENGTH_LABEL}. @item PASSPHRASE_READ_BELOW_FREE @code{passphrase_read2} may do as it please with the line below the current line. This is only used @@ -414,9 +418,6 @@ escape sequence, followed by a new line or whitespace; the rest of the is ignored. The program must also accept the flag @code{-r}, telling it not to discard any input. - - - @end table @@ -426,7 +427,7 @@ In addition, you may use the follow flags. @item @code{PASSPHRASE_STAR_CHAR} The text to print instead of the character `*' when -@code{PASSPHRASE_STAR} is used. For example you may run +@code{PASSPHRASE_STAR} is used. For example, you may run @example make OPTIONS=PASSPHRASE_STAR \ PASSPHRASE_STAR_CHAR="#" @@ -434,7 +435,7 @@ make OPTIONS=PASSPHRASE_STAR \ @item @code{PASSPHRASE_TEXT_EMPTY} The text to print instead of the `(empty)' when -@code{PASSPHRASE_TEXT} is used. For example you may run +@code{PASSPHRASE_TEXT} is used. For example, you may run @example make OPTIONS=PASSPHRASE_TEXT \ PASSPHRASE_TEXT_EMPTY="there is nothing here" @@ -442,12 +443,22 @@ make OPTIONS=PASSPHRASE_TEXT \ @item @code{PASSPHRASE_TEXT_NOT_EMPTY} The text to print instead of the `(not empty)' when -@code{PASSPHRASE_TEXT} is used. For example you may run +@code{PASSPHRASE_TEXT} is used. For example, you may run @example make OPTIONS=PASSPHRASE_TEXT \ PASSPHRASE_TEXT_NOT_EMPTY="there is something here" @end example +@item @code{LIBPASSPHRASE_STRENGTH_LABEL} +The text to print instead of the `Strength:' when +@code{PASSPHRASE_METER} is used and a new passphrase +is being entered. For example, you may run +@example +make OPTIONS=PASSPHRASE_METER \ + LIBPASSPHRASE_STRENGTH_LABEL="Hope meter:" +@end example + + @end table 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 |