aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-12-05 16:42:17 +0100
committerMattias Andrée <maandree@operamail.com>2015-12-05 16:42:17 +0100
commite5c01e102c790a918ecfda66cfce7cb5e5f8af0a (patch)
treed2ab239d8a3d664c793b3d35fd34e9f0030cede2
parentadd description of strength value (diff)
downloadlibpassphrase-e5c01e102c790a918ecfda66cfce7cb5e5f8af0a.tar.gz
libpassphrase-e5c01e102c790a918ecfda66cfce7cb5e5f8af0a.tar.bz2
libpassphrase-e5c01e102c790a918ecfda66cfce7cb5e5f8af0a.tar.xz
customisable meter
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile3
-rw-r--r--info/libpassphrase.texinfo30
-rw-r--r--src/passphrase.c11
-rw-r--r--src/passphrase_helper.h19
4 files changed, 53 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 5e85083..8526dd7 100644
--- a/Makefile
+++ b/Makefile
@@ -75,6 +75,9 @@ WARN = -Wall -Wextra -Wdouble-promotion -Wformat=2 -Winit-self -Wmissing-include
STD = gnu99
# C preprocessor flags
CPPFLAGS_ = $(foreach D, $(OPTIONS), -D'$(D)=1') $(foreach D, $(QUOTED_OPTIONS), -D'$(D)="$($(D))"')
+ifdef PASSPHRASE_STRENGTH_LIMITS_HEADER
+CPPFLAGS_ += -D'PASSPHRASE_STRENGTH_LIMITS_HEADER=$(PASSPHRASE_STRENGTH_LIMITS_HEADER)'
+endif
# C compiling flags
CFLAGS_ = -std=$(STD) $(WARN)
# Linking flags
diff --git a/info/libpassphrase.texinfo b/info/libpassphrase.texinfo
index 8b76067..7d46aaa 100644
--- a/info/libpassphrase.texinfo
+++ b/info/libpassphrase.texinfo
@@ -458,7 +458,35 @@ make OPTIONS=PASSPHRASE_METER \
LIBPASSPHRASE_STRENGTH_LABEL="Hope meter:"
@end example
-
+@item @code{PASSPHRASE_STRENGTH_LIMITS_HEADER}
+A header file to include that defines the macro
+@code{LIST_PASSPHRASE_STRENGTH_LIMITS}. If used,
+this value should either be a system header file and
+enclosed in ASCII angle brackets, or a local header
+file relative to the @file{src/passphrase_helper.h}
+and enclosed in ASCII double quotes.
+
+The @code{LIST_PASSPHRASE_STRENGTH_LIMITS} should
+be define similar to
+@example
+#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")
+@end example
+The macro @code{X} is defined when the macro
+[@code{LIST_PASSPHRASE_STRENGTH_LIMITS}] is used.
+Its first argument should evalute to truth if
+@code{V} from @code{LIST_PASSPHRASE_STRENGTH_LIMITS}
+can be designed in the string in the third argument.
+It is important that it [the first argument] always
+evaluates to truth for the last expansion of the macro
+[@code{X}]. The second argument is the Select Graphic
+Rendition parameters --- semi-colon separate -- used
+to colour the description (the third argument).
@end table
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)