01: package org.manentia.kasai.user.passwordvalidators;
02:
03: import java.util.ResourceBundle;
04:
05: import org.apache.commons.lang.CharUtils;
06: import org.apache.commons.lang.StringUtils;
07: import org.apache.commons.lang.math.NumberUtils;
08: import org.manentia.kasai.Constants;
09:
10: public class DifferentCharactersPasswordValidator implements
11: PasswordValidator {
12:
13: public boolean validate(String password) {
14: boolean result = false;
15:
16: ResourceBundle res = ResourceBundle
17: .getBundle(Constants.CONFIG_PROPERTY_FILE);
18: int minNumeric = NumberUtils
19: .toInt(res
20: .getString("differentCharactersPasswordValidator.minNumeric"));
21: int minAlpha = NumberUtils
22: .toInt(res
23: .getString("differentCharactersPasswordValidator.minAlpha"));
24: int minOther = NumberUtils
25: .toInt(res
26: .getString("differentCharactersPasswordValidator.minOther"));
27:
28: password = StringUtils.defaultString(password);
29:
30: int numericCount = 0;
31: int alphaCount = 0;
32: int otherCount = 0;
33:
34: for (char c : password.toCharArray()) {
35: if (CharUtils.isAsciiAlpha(c)) {
36: alphaCount++;
37: } else if (CharUtils.isAsciiNumeric(c)) {
38: numericCount++;
39: } else {
40: otherCount++;
41: }
42: }
43:
44: if (numericCount >= minNumeric && alphaCount >= minAlpha
45: && otherCount >= minOther) {
46: result = true;
47: }
48:
49: return result;
50: }
51:
52: }
|