From 57944f6147f077ccf4d84b9d2659f4e8645e8858 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 8 Mar 2018 15:01:45 +0100 Subject: Reastructure master password functionality --- libsylph/account.c | 49 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) (limited to 'libsylph/account.c') diff --git a/libsylph/account.c b/libsylph/account.c index e4cb5cc..7440434 100644 --- a/libsylph/account.c +++ b/libsylph/account.c @@ -37,7 +37,7 @@ #include "utils.h" #include "sylmain.h" #include "prefs_common.h" -#include "ssl.h" +#include "masterpassword.h" PrefsAccount *cur_account; @@ -55,50 +55,17 @@ void account_read_config_all(void) gchar buf[PREFSBUFSIZE]; PrefsAccount *ac_prefs; #if USE_SSL - 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; - } + /* allow 3 attempts to enter the master password */ + if (check_master_password_interactively(3) != 0) { + /* master password does not match the hash */ + 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; - } - g_free(master_password); - g_free(master_password_confirm); - master_password = NULL; - } + set_master_password_interactively(3); } /* TODO: Warning if password is NULL */ } else { -- cgit v1.3