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

[firstboot] Fix username guessing with unicode chars (#677904)



---
 modules/create_user.py |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/modules/create_user.py b/modules/create_user.py
index d162fad..7628364 100644
--- a/modules/create_user.py
+++ b/modules/create_user.py
@@ -22,6 +22,7 @@ import libuser
 import os, string, sys, time
 import os.path
 import pwd
+import unicodedata
 
 from firstboot.config import *
 from firstboot.constants import *
@@ -413,10 +414,16 @@ class moduleClass(Module):
         try:
             user = name.split()[0]
         except IndexError:
-            user = ""
-        else:
-            user = user.encode("ascii", "ascii_transliterate")
+            user = u""
+
+        # convert to ascii (try to replace characters)
+        try:
+            nfkd = unicodedata.normalize("NFKD", user)
+            user = u"".join([c for c in nfkd if not unicodedata.combining(c)])
+            user = user.encode("ascii", "ignore")
             user = user.lower()
+        except:
+            user = ""
 
         self.usernameEntry.handler_block_by_func(self.usernameEntry_changed)
         self.usernameEntry.set_text(user)
-- 
1.7.3.2


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