]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/util/PasswordStrengthChecker.java
Implement a Template-Foreach (and use in "new email certificate")
[gigi.git] / src / org / cacert / gigi / util / PasswordStrengthChecker.java
index 0f72664e5b823b131b46e2f88f6e28e70f0cf187..cad2aba58106f21a872a41d32f80f5094174f4e6 100644 (file)
@@ -9,10 +9,12 @@ public class PasswordStrengthChecker {
        static Pattern lower = Pattern.compile("[a-z]");
        static Pattern upper = Pattern.compile("[A-Z]");
        static Pattern whitespace = Pattern.compile("\\s");
-       static Pattern special = Pattern.compile("\\W");
+       static Pattern special = Pattern.compile("(?!\\s)\\W");
+
        private PasswordStrengthChecker() {
        }
-       public static int checkpwlight(String pw) {
+
+       private static int checkpwlight(String pw) {
                int points = 0;
                if (pw.length() > 15) {
                        points++;
@@ -43,7 +45,11 @@ public class PasswordStrengthChecker {
                }
                return points;
        }
+
        public static int checkpw(String pw, User u) {
+               if (pw == null) {
+                       return 0;
+               }
                int light = checkpwlight(pw);
                if (contained(pw, u.getEmail())) {
                        light -= 2;
@@ -63,6 +69,7 @@ public class PasswordStrengthChecker {
                // TODO dictionary check
                return light;
        }
+
        private static boolean contained(String pw, String check) {
                if (check == null || check.equals("")) {
                        return false;