1 package org.cacert.gigi.util;
3 import java.util.regex.Pattern;
5 import org.cacert.gigi.User;
7 public class PasswordStrengthChecker {
8 static Pattern digits = Pattern.compile("\\d");
9 static Pattern lower = Pattern.compile("[a-z]");
10 static Pattern upper = Pattern.compile("[A-Z]");
11 static Pattern whitespace = Pattern.compile("\\s");
12 static Pattern special = Pattern.compile("(?!\\s)\\W");
14 private PasswordStrengthChecker() {
17 private static int checkpwlight(String pw) {
19 if (pw.length() > 15) {
22 if (pw.length() > 20) {
25 if (pw.length() > 25) {
28 if (pw.length() > 30) {
31 if (digits.matcher(pw).find()) {
34 if (lower.matcher(pw).find()) {
37 if (upper.matcher(pw).find()) {
40 if (special.matcher(pw).find()) {
43 if (whitespace.matcher(pw).find()) {
49 public static int checkpw(String pw, User u) {
53 int light = checkpwlight(pw);
54 if (contained(pw, u.getEmail())) {
57 if (contained(pw, u.getFname())) {
60 if (contained(pw, u.getLname())) {
63 if (contained(pw, u.getMname())) {
66 if (contained(pw, u.getSuffix())) {
69 // TODO dictionary check
73 private static boolean contained(String pw, String check) {
74 if (check == null || check.equals("")) {
77 if (pw.contains(check)) {
80 if (check.contains(pw)) {