changeset 4459:fc4e32fdd922

remove exception handling from password checker because exceptions can't deal with unicode correctly
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 14 Dec 2008 14:05:32 +0100
parents 1772b4d6ea11
children 186adde1df66
files MoinMoin/config/multiconfig.py
diffstat 1 files changed, 20 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Sat Dec 13 19:29:10 2008 +0100
+++ b/MoinMoin/config/multiconfig.py	Sun Dec 14 14:05:32 2008 +0100
@@ -649,33 +649,30 @@
         If you don't want to check passwords, use password_checker = None.
 
         @return: None if there is no problem with the password,
-                 some string with an error msg, if the password is problematic.
+                 some unicode object with an error msg, if the password is problematic.
     """
     _ = request.getText
-    try:
-        # in any case, do a very simple built-in check to avoid the worst passwords
-        if len(password) < 6:
-            raise ValueError(_("Password is too short."))
-        if len(set(password)) < 4:
-            raise ValueError(_("Password has not enough different characters."))
+    # in any case, do a very simple built-in check to avoid the worst passwords
+    if len(password) < 6:
+        return _("Password is too short.")
+    if len(set(password)) < 4:
+        return _("Password has not enough different characters.")
 
-        username_lower = username.lower()
-        password_lower = password.lower()
-        if username in password or password in username or \
-           username_lower in password_lower or password_lower in username_lower:
-            raise ValueError(_("Password is too easy (password contains name or name contains password)."))
+    username_lower = username.lower()
+    password_lower = password.lower()
+    if username in password or password in username or \
+       username_lower in password_lower or password_lower in username_lower:
+        return _("Password is too easy (password contains name or name contains password).")
 
-        keyboards = (ur"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./", # US kbd
-                     ur"^1234567890ß´qwertzuiopü+asdfghjklöä#yxcvbnm,.-", # german kbd
-                    ) # add more keyboards!
-        for kbd in keyboards:
-            rev_kbd = kbd[::-1]
-            if password in kbd or password in rev_kbd or \
-               password_lower in kbd or password_lower in rev_kbd:
-                raise ValueError(_("Password is too easy (keyboard sequence)."))
-        return None
-    except ValueError, err:
-        return unicode(err)
+    keyboards = (ur"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./", # US kbd
+                 ur"^1234567890ß´qwertzuiopü+asdfghjklöä#yxcvbnm,.-", # german kbd
+                ) # add more keyboards!
+    for kbd in keyboards:
+        rev_kbd = kbd[::-1]
+        if password in kbd or password in rev_kbd or \
+           password_lower in kbd or password_lower in rev_kbd:
+            return _("Password is too easy (keyboard sequence).")
+    return None
 
 
 class DefaultExpression(object):