X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Futil%2FPasswordStrengthChecker.java;h=3e4760bbf2b86c47fd53766fbbe5be89b26e0327;hb=3252dc36fadd1a7e5f13bc01401e10565d61f635;hp=0f72664e5b823b131b46e2f88f6e28e70f0cf187;hpb=b0ab4664edfc6ee90b658bfa662a54dec42879b3;p=gigi.git diff --git a/src/org/cacert/gigi/util/PasswordStrengthChecker.java b/src/org/cacert/gigi/util/PasswordStrengthChecker.java index 0f72664e..3e4760bb 100644 --- a/src/org/cacert/gigi/util/PasswordStrengthChecker.java +++ b/src/org/cacert/gigi/util/PasswordStrengthChecker.java @@ -2,6 +2,7 @@ package org.cacert.gigi.util; import java.util.regex.Pattern; +import org.cacert.gigi.GigiApiException; import org.cacert.gigi.User; public class PasswordStrengthChecker { @@ -9,10 +10,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 +46,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 +70,14 @@ public class PasswordStrengthChecker { // TODO dictionary check return light; } + + public static void assertStrongPassword(String pw, User u) throws GigiApiException { + if (checkpw(pw, u) < 3) { + throw new GigiApiException("The Pass Phrase you submitted failed to contain enough" + + " differing characters and/or contained words from" + " your name and/or email address."); + } + } + private static boolean contained(String pw, String check) { if (check == null || check.equals("")) { return false;