X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Futil%2FPasswordStrengthChecker.java;h=cad2aba58106f21a872a41d32f80f5094174f4e6;hb=ca82909d6bb910769eb756058d51d55e6d257914;hp=373079922cb90f0414920bd153d9a63419073ab6;hpb=36e2db1e1181b26f18a1615a2deddbb299569708;p=gigi.git diff --git a/src/org/cacert/gigi/util/PasswordStrengthChecker.java b/src/org/cacert/gigi/util/PasswordStrengthChecker.java index 37307992..cad2aba5 100644 --- a/src/org/cacert/gigi/util/PasswordStrengthChecker.java +++ b/src/org/cacert/gigi/util/PasswordStrengthChecker.java @@ -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,8 +69,9 @@ public class PasswordStrengthChecker { // TODO dictionary check return light; } + private static boolean contained(String pw, String check) { - if (check == null) { + if (check == null || check.equals("")) { return false; } if (pw.contains(check)) {