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("\\W");
13 private PasswordStrengthChecker() {
15 private static int checkpwlight(String pw) {
17 if (pw.length() > 15) {
20 if (pw.length() > 20) {
23 if (pw.length() > 25) {
26 if (pw.length() > 30) {
29 if (digits.matcher(pw).find()) {
32 if (lower.matcher(pw).find()) {
35 if (upper.matcher(pw).find()) {
38 if (special.matcher(pw).find()) {
41 if (whitespace.matcher(pw).find()) {
46 public static int checkpw(String pw, User u) {
50 int light = checkpwlight(pw);
51 if (contained(pw, u.getEmail())) {
54 if (contained(pw, u.getFname())) {
57 if (contained(pw, u.getLname())) {
60 if (contained(pw, u.getMname())) {
63 if (contained(pw, u.getSuffix())) {
66 // TODO dictionary check
69 private static boolean contained(String pw, String check) {
70 if (check == null || check.equals("")) {
73 if (pw.contains(check)) {
76 if (check.contains(pw)) {