[gtk/peek-password: 13/14] gtk-demo: Show password strength
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/peek-password: 13/14] gtk-demo: Show password strength
- Date: Fri, 15 Mar 2019 00:44:47 +0000 (UTC)
commit d3d65e9148b10319e7c32b505e7039ae3d308b76
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Mar 13 20:37:42 2019 -0400
gtk-demo: Show password strength
Make the password entry demo show password strength.
demos/gtk-demo/password_entry.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
---
diff --git a/demos/gtk-demo/password_entry.c b/demos/gtk-demo/password_entry.c
index b7083286bd..a30fd35174 100644
--- a/demos/gtk-demo/password_entry.c
+++ b/demos/gtk-demo/password_entry.c
@@ -27,6 +27,19 @@ update_button (GObject *object,
text[0] != '\0' && g_str_equal (text, text2));
}
+static int
+get_strength (GtkPasswordEntry *entry)
+{
+ const char *text;
+ int strength;
+
+ text = gtk_editable_get_text (GTK_EDITABLE (entry));
+
+ strength = CLAMP (10 * strlen (text), 0, 100);
+
+ return strength;
+}
+
GtkWidget *
do_password_entry (GtkWidget *do_widget)
{
@@ -59,6 +72,8 @@ do_password_entry (GtkWidget *do_widget)
"activates-default", TRUE,
NULL);
g_signal_connect (entry, "notify::text", G_CALLBACK (update_button), NULL);
+ gtk_password_entry_set_show_strength (GTK_PASSWORD_ENTRY (entry), TRUE);
+ g_signal_connect (entry, "get-strength", G_CALLBACK (get_strength), NULL);
gtk_container_add (GTK_CONTAINER (box), entry);
entry2 = gtk_password_entry_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]