#include "password.h"
#include "prefs_common.h"
-static void entry_new1_activated(GtkEntry *entry, gpointer user_data)
+static void entry_activated(GtkEntry *entry, gpointer user_data)
{
const gchar *text = gtk_entry_get_text(entry);
struct _ctx {
gboolean done;
GtkWidget *dialog;
+ GtkWidget *entry_old;
GtkWidget *entry_new1;
GtkWidget *entry_new2;
};
static void ok_button_clicked(GtkButton *button, gpointer user_data)
{
struct _ctx *ctx = (struct _ctx *)user_data;
+ const gchar *old = NULL;
const gchar *new1 = gtk_entry_get_text(GTK_ENTRY(ctx->entry_new1));
const gchar *new2 = gtk_entry_get_text(GTK_ENTRY(ctx->entry_new2));
debug_print("OK button activated\n");
- /* Now we check the new password - same in both entries. */
+ /* Now we check the new passphrase - same in both entries. */
if (strcmp(new1, new2)) {
- debug_print("passwords do not match\n");
- alertpanel_warning(_("New passwords do not match, try again."));
+ debug_print("passphrases do not match\n");
+ alertpanel_warning(_("New passwphrases do not match, try again."));
gtk_entry_set_text(GTK_ENTRY(ctx->entry_new1), "");
gtk_entry_set_text(GTK_ENTRY(ctx->entry_new2), "");
gtk_widget_grab_focus(ctx->entry_new1);
return;
}
- master_password_change(new1);
+ /* If there is an existing master passphrase, check for its correctness
+ * in entry_old. */
+ if (master_passphrase_is_set()
+ && ((old = gtk_entry_get_text(GTK_ENTRY(ctx->entry_old))) == NULL
+ || strlen(old) == 0 || !master_passphrase_is_correct(old))) {
+ debug_print("old passphrase incorrect\n");
+ alertpanel_warning(_("Incorrect old master passphrase entered, try again."));
+ gtk_entry_set_text(GTK_ENTRY(ctx->entry_old), "");
+ gtk_widget_grab_focus(ctx->entry_old);
+ return;
+ }
+
+ master_passphrase_change(old, new1);
ctx->done = TRUE;
gtk_widget_destroy(ctx->dialog);
ctx->dialog = NULL;
}
-void master_password_change_dialog()
+void master_passphrase_change_dialog()
{
static PangoFontDescription *font_desc;
GtkWidget *dialog;
GtkWidget *vbox, *hbox;
GtkWidget *icon, *table, *label;
GtkWidget *msg_title;
- GtkWidget *entry_new1, *entry_new2;
+ GtkWidget *entry_old, *entry_new1, *entry_new2;
GtkWidget *confirm_area;
GtkWidget *ok_button, *cancel_button;
struct _ctx *ctx;
gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show(vbox);
- msg_title = gtk_label_new(_("Changing master password"));
+ msg_title = gtk_label_new(_("Changing master passphrase"));
gtk_misc_set_alignment(GTK_MISC(msg_title), 0, 0.5);
gtk_label_set_justify(GTK_LABEL(msg_title), GTK_JUSTIFY_LEFT);
gtk_label_set_use_markup (GTK_LABEL (msg_title), TRUE);
if (font_desc)
gtk_widget_modify_font(msg_title, font_desc);
- label = gtk_label_new("<some useful text goes here>");
+ label = gtk_label_new(
+ _("If a master passphrase is currently active, it\n"
+ "needs to be entered.")
+ );
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
gtk_widget_show(label);
- table = gtk_table_new(2, 2, FALSE);
+ table = gtk_table_new(4, 2, FALSE);
- label = gtk_label_new(_("New password:"));
+ /* Old passphrase */
+ label = gtk_label_new(_("Old passphrase:"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
GTK_EXPAND | GTK_FILL, 0, 0, 0);
+ entry_old = gtk_entry_new();
+ gtk_entry_set_visibility(GTK_ENTRY(entry_old), FALSE);
+ gtk_table_attach(GTK_TABLE(table), entry_old, 1, 2, 0, 1,
+ GTK_FILL | GTK_EXPAND, 0, 0, 0);
+
+ /* Separator */
+ gtk_table_attach(GTK_TABLE(table),
+ gtk_hseparator_new(), 0, 2, 1, 2,
+ GTK_FILL | GTK_EXPAND, 0, 0, 5);
+
+ /* New passphrase */
+ label = gtk_label_new(_("New passphrase:"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3,
+ GTK_EXPAND | GTK_FILL, 0, 0, 0);
+
entry_new1 = gtk_entry_new();
gtk_entry_set_visibility(GTK_ENTRY(entry_new1), FALSE);
- gtk_table_attach(GTK_TABLE(table), entry_new1, 1, 2, 0, 1,
+ gtk_table_attach(GTK_TABLE(table), entry_new1, 1, 2, 2, 3,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
- label = gtk_label_new(_("New password (again):"));
+ /* New passphrase again */
+ label = gtk_label_new(_("Confirm passphrase:"));
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
- gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
+ gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4,
GTK_EXPAND | GTK_FILL, 0, 0, 0);
entry_new2 = gtk_entry_new();
gtk_entry_set_visibility(GTK_ENTRY(entry_new2), FALSE);
- gtk_table_attach(GTK_TABLE(table), entry_new2, 1, 2, 1, 2,
+ gtk_table_attach(GTK_TABLE(table), entry_new2, 1, 2, 3, 4,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
+ /* Dialog buttons */
gtkut_stock_button_set_create(&confirm_area,
&cancel_button, GTK_STOCK_CANCEL,
&ok_button, GTK_STOCK_OK,
gtk_widget_grab_default(ok_button);
+ /* If no master passphrase is set, disable the "old passphrase" entry */
+ if (!master_passphrase_is_set())
+ gtk_widget_set_sensitive(entry_old, FALSE);
+
+ g_signal_connect(G_OBJECT(entry_old), "activate",
+ G_CALLBACK(entry_activated), entry_new1);
g_signal_connect(G_OBJECT(entry_new1), "activate",
- G_CALLBACK(entry_new1_activated), entry_new2);
+ G_CALLBACK(entry_activated), entry_new2);
gtk_entry_set_activates_default(GTK_ENTRY(entry_new2), TRUE);
ctx = g_new(struct _ctx, 1);
ctx->done = FALSE;
ctx->dialog = dialog;
+ ctx->entry_old = entry_old;
ctx->entry_new1 = entry_new1;
ctx->entry_new2 = entry_new2;
while (!ctx->done)
gtk_main_iteration();
- manage_window_focus_out(dialog, NULL, NULL);
-
if (ctx->dialog != NULL)
gtk_widget_destroy(ctx->dialog);