From e5c01e102c790a918ecfda66cfce7cb5e5f8af0a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 5 Dec 2015 16:42:17 +0100 Subject: customisable meter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/passphrase.c | 11 ++++------- src/passphrase_helper.h | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/passphrase.c b/src/passphrase.c index 33c7276..01e96cb 100644 --- a/src/passphrase.c +++ b/src/passphrase.c @@ -307,13 +307,10 @@ 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 (0); +#define X(COND, COLOUR, DESC) else if (COND) desc = COLOUR"m"DESC; + LIST_PASSPHRASE_STRENGTH_LIMITS(value) +#undef X if (state->flags & PASSPHRASE_READ_SCREEN_FREE) fprintf(stderr, "\033[s\033[E\033[0K%s \033[%s\033[m (%lli)\033[u", state->label, desc, value); diff --git a/src/passphrase_helper.h b/src/passphrase_helper.h index e41ca0c..ccc927d 100644 --- a/src/passphrase_helper.h +++ b/src/passphrase_helper.h @@ -20,6 +20,7 @@ #define PASSPHRASE_HELPER_H + /* Fix conflicting configurations */ #if defined(PASSPHRASE_TEXT) && defined(PASSPHRASE_STAR) # warning You cannot have both PASSPHRASE_TEXT and PASSPHRASE_STAR @@ -50,8 +51,22 @@ #endif +/* Strength limits and descriptions */ +#ifdef PASSPHRASE_STRENGTH_LIMITS_HEADER +# include PASSPHRASE_STRENGTH_LIMITS_HEADER +#else +# define LIST_PASSPHRASE_STRENGTH_LIMITS(V) \ + X(V == 0, "1;31", "Well-known common password") \ + X(V <= 150, "31", "Extremely week") \ + X(V <= 200, "33", "Week") \ + X(V <= 250, "32", "Good") \ + X(V <= 350, "1;32", "Strong") \ + X(1, "1;7;32", "Perfect") +#endif + + -/* Control keys. */ +/* Control keys */ /** * Home-key. @@ -102,7 +117,7 @@ -/* Use by macros below to ensure that the result is not used. */ +/* Use by macros below to ensure that the result is not used */ #define VOID(...) do { __VA_ARGS__; } while (0) -- cgit v1.2.3-70-g09d2