From a949a98e583436533e19e392486c7eca0ac2bab6 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 7 Mar 2018 09:33:26 +0100 Subject: Make some master password hash cleanups --- libsylph/account.c | 77 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/libsylph/account.c b/libsylph/account.c index 05d5871..e4cb5cc 100644 --- a/libsylph/account.c +++ b/libsylph/account.c @@ -55,49 +55,52 @@ void account_read_config_all(void) gchar buf[PREFSBUFSIZE]; PrefsAccount *ac_prefs; #if USE_SSL - guint cnt; + guint cnt; gchar *master_password, *master_password_confirm; if (prefs_common.use_master_password) { if (prefs_common.master_password_hash != NULL) { - for (cnt = 0; cnt < 3; ++cnt) { - /* allow 3 attempts to enter the master password */ - master_password = input_query_password(_("Sylpheed"), - _("Master password")); - if (check_password( - master_password, - prefs_common.master_password_hash) == RC_OK) { - break; - } - debug_print(_("Wrong master password entered (%d)\n"), cnt); - g_free(master_password); - master_password = NULL; - } - /* TODO: Warning if password is NULL */ + for (cnt = 0; cnt < 3; ++cnt) { + /* allow 3 attempts to enter the master password */ + master_password = input_query_password(_("Sylpheed"), + _("Master password")); + if (check_password( + master_password, + prefs_common.master_password_hash) == RC_OK) { + break; + } + debug_print(_("Wrong master password entered (%d)\n"), cnt); + g_free(master_password); + master_password = NULL; + } } else { /* No master password set (no master_password_hash) */ - for (cnt = 0; cnt < 3; ++cnt) { - master_password = input_query_password(_("Sylpheed"), - _("Master password")); - master_password_confirm = input_query_password( - _("Sylpheed"), - _("Master password confirmation")); - if (strcmp(master_password, master_password_confirm) == 0) { - /* The passwords match */ - g_free(master_password_confirm); - if (generate_password_hash( - &prefs_common.master_password_hash, - master_password, - NULL) != RC_OK) { - debug_print( - _("Could not generate master password hash")); - g_free(master_password); - continue; - } - prefs_common_write_config(); - break; - } - } + for (cnt = 0; cnt < 3; ++cnt) { + master_password = input_query_password(_("Sylpheed"), + _("Master password")); + master_password_confirm = input_query_password( + _("Sylpheed"), + _("Master password confirmation")); + if (strcmp(master_password, master_password_confirm) == 0) { + /* The passwords match */ + g_free(master_password_confirm); + if (generate_password_hash( + &prefs_common.master_password_hash, + master_password, + NULL) != RC_OK) { + debug_print( + _("Could not generate master password hash")); + g_free(master_password); + continue; + } + prefs_common_write_config(); + break; + } + g_free(master_password); + g_free(master_password_confirm); + master_password = NULL; + } } + /* TODO: Warning if password is NULL */ } else { master_password = NULL; } -- cgit v1.3