[gnome-control-center/gnome-3-8] user-accounts: Disallow whitespace-only names



commit b2e20a721d832cde0f7a467640f82d132c66306b
Author: Chris Cummins <christopher e cummins intel com>
Date:   Wed May 8 16:55:16 2013 +0100

    user-accounts: Disallow whitespace-only names
    
    This prevents users from creating an account with a full name consisting
    solely of whitespace, e.g., space and tab characters. Having "invisible"
    real names can cause confusion on the login screen.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=699940

 panels/user-accounts/um-utils.c |   25 ++++++++++++++++++++++---
 1 files changed, 22 insertions(+), 3 deletions(-)
---
diff --git a/panels/user-accounts/um-utils.c b/panels/user-accounts/um-utils.c
index 69868a0..9c45b34 100644
--- a/panels/user-accounts/um-utils.c
+++ b/panels/user-accounts/um-utils.c
@@ -468,11 +468,30 @@ is_username_used (const gchar *username)
 gboolean
 is_valid_name (const gchar *name)
 {
-        gboolean valid;
+        gboolean is_empty = TRUE;
+        const gchar *c;
 
-        valid = (strlen (name) > 0);
+        /* Valid names must contain:
+         *   1) at least one character.
+         *   2) at least one non-"space" character.
+         */
+        for (c = name; *c; c++) {
+                gunichar unichar;
 
-        return valid;
+                unichar = g_utf8_get_char_validated (c, -1);
+
+                /* Partial UTF-8 sequence or end of string */
+                if (unichar == (gunichar) -1 || unichar == (gunichar) -2)
+                        break;
+
+                /* Check for non-space character */
+                if (!g_unichar_isspace (unichar)) {
+                        is_empty = FALSE;
+                        break;
+                }
+        }
+
+        return !is_empty;
 }
 
 gboolean


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