[gnome-keyring] [prompt] Add the password strength indicator to new prompt.



commit 20408620d8f91848804f3dd5316ec2ce4e063675
Author: Stef Walter <stef memberwebs com>
Date:   Sat Dec 19 14:37:52 2009 +0000

    [prompt] Add the password strength indicator to new prompt.

 daemon/prompt/gkd-prompt-tool.c |   61 ++++++++++++++++++++++++++++++++++++++-
 daemon/prompt/gkd-prompt.ui     |   60 +++++++++++++++++++++++++++++++-------
 2 files changed, 109 insertions(+), 12 deletions(-)
---
diff --git a/daemon/prompt/gkd-prompt-tool.c b/daemon/prompt/gkd-prompt-tool.c
index 0afe587..7d034f4 100644
--- a/daemon/prompt/gkd-prompt-tool.c
+++ b/daemon/prompt/gkd-prompt-tool.c
@@ -104,6 +104,61 @@ window_state_changed (GtkWidget *win, GdkEventWindowState *event, gpointer data)
 	return FALSE;
 }
 
+
+static void
+on_password_changed (GtkEditable *editable, gpointer user_data)
+{
+	const char *password;
+	int length, i;
+	int upper, lower, digit, misc;
+	gdouble pwstrength;
+
+	password = gtk_entry_get_text (GTK_ENTRY (editable));
+
+	/*
+	 * This code is based on the Master Password dialog in Firefox
+	 * (pref-masterpass.js)
+	 * Original code triple-licensed under the MPL, GPL, and LGPL
+	 * so is license-compatible with this file
+	 */
+
+	length = strlen (password);
+	upper = 0;
+	lower = 0;
+	digit = 0;
+	misc = 0;
+
+	for ( i = 0; i < length ; i++) {
+		if (g_ascii_isdigit (password[i]))
+			digit++;
+		else if (g_ascii_islower (password[i]))
+			lower++;
+		else if (g_ascii_isupper (password[i]))
+			upper++;
+		else
+			misc++;
+	}
+
+	if (length > 5)
+		length = 5;
+	if (digit > 3)
+		digit = 3;
+	if (upper > 3)
+		upper = 3;
+	if (misc > 3)
+		misc = 3;
+
+	pwstrength = ((length*0.1)-0.2) + (digit*0.1) + (misc*0.15) + (upper*0.1);
+
+	if (pwstrength < 0.0)
+		pwstrength = 0.0;
+	if (pwstrength > 1.0)
+		pwstrength = 1.0;
+
+	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (user_data), pwstrength);
+}
+
+
 static void
 prepare_visibility (GtkBuilder *builder, GtkDialog *dialog)
 {
@@ -222,10 +277,14 @@ static void
 prepare_passwords (GtkBuilder *builder, GtkDialog *dialog)
 {
 	GtkEntry *entry;
+	GtkWidget *strength;
 
 	entry = GTK_ENTRY(gtk_builder_get_object (builder, "password_entry"));
 	prepare_password_entry (entry);
 
+	strength = GTK_WIDGET (gtk_builder_get_object (builder, "strength_bar"));
+	g_signal_connect (entry, "changed", G_CALLBACK (on_password_changed), strength);
+
 	entry = GTK_ENTRY(gtk_builder_get_object (builder, "original_entry"));
 	prepare_password_entry (entry);
 
@@ -261,9 +320,9 @@ prepare_dialog (GtkBuilder *builder)
 	dialog = GTK_DIALOG (gtk_builder_get_object (builder, "prompt_dialog"));
 	g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
 
+	prepare_visibility (builder, dialog);
 	prepare_titlebar (builder, dialog);
 	prepare_prompt (builder, dialog);
-	prepare_visibility (builder, dialog);
 	prepare_buttons (builder, dialog);
 	prepare_passwords (builder, dialog);
 	prepare_security (builder, dialog);
diff --git a/daemon/prompt/gkd-prompt.ui b/daemon/prompt/gkd-prompt.ui
index ad5fc8d..0125619 100644
--- a/daemon/prompt/gkd-prompt.ui
+++ b/daemon/prompt/gkd-prompt.ui
@@ -167,28 +167,65 @@ An application wants access to the keyring 'xxx', but it is locked.</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkHBox" id="confirm_area">
+                          <object class="GtkVBox" id="confirm_area">
                             <property name="visible">True</property>
+                            <property name="orientation">vertical</property>
                             <property name="spacing">6</property>
                             <child>
-                              <object class="GtkLabel" id="confirm_label">
+                              <object class="GtkHBox" id="confirm_box">
                                 <property name="visible">True</property>
-                                <property name="xalign">0</property>
-                                <property name="label" translatable="yes">_Confirm:</property>
-                                <property name="use_underline">True</property>
+                                <property name="spacing">6</property>
+                                <child>
+                                  <object class="GtkLabel" id="confirm_label">
+                                    <property name="visible">True</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" translatable="yes">_Confirm:</property>
+                                    <property name="use_underline">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkEntry" id="confirm_entry">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="visibility">False</property>
+                                    <property name="invisible_char">&#x2022;</property>
+                                    <property name="activates_default">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
                               </object>
                               <packing>
-                                <property name="expand">False</property>
                                 <property name="position">0</property>
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkEntry" id="confirm_entry">
+                              <object class="GtkHBox" id="hbox3">
                                 <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                                <property name="visibility">False</property>
-                                <property name="invisible_char">&#x2022;</property>
-                                <property name="activates_default">True</property>
+                                <property name="spacing">6</property>
+                                <child>
+                                  <object class="GtkLabel" id="strength_label">
+                                    <property name="visible">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkProgressBar" id="strength_bar">
+                                    <property name="visible">True</property>
+                                    <property name="text" translatable="yes">New password strength</property>
+                                  </object>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
                               </object>
                               <packing>
                                 <property name="position">1</property>
@@ -445,6 +482,7 @@ An application wants access to the keyring 'xxx', but it is locked.</property>
       <widget name="original_label"/>
       <widget name="password_label"/>
       <widget name="confirm_label"/>
+      <widget name="strength_label"/>
     </widgets>
   </object>
 </interface>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]