use of org.passay.LengthRule in project dataverse by IQSS.
the class PasswordValidatorServiceBean method addStandardValidator.
/**
* standardValidator
* <p>
* Apply Rules 1, 2 and 3.
*/
private void addStandardValidator() {
int maxLength = getMaxLength();
int minLength = getMinLength();
int numberOfCharacteristics = getNumberOfCharacteristics();
int numberOfConsecutiveDigitsAllowed = getNumberOfConsecutiveDigitsAllowed();
PasswordValidator passwordValidator = validators.get(ValidatorTypes.StandardValidator);
if (passwordValidator == null) {
final List<Rule> rules = new ArrayList<>(4);
rules.add(dictionarySubstringRule());
final LengthRule lengthRule = new LengthRule();
if (maxLength != 0) {
lengthRule.setMaximumLength(maxLength);
}
if (minLength != 0) {
lengthRule.setMinimumLength(minLength);
}
rules.add(lengthRule);
if (numberOfCharacteristics != 0) {
rules.add(characterRule(getCharacterRules()));
}
rules.add(repeatingDigitsRule(numberOfConsecutiveDigitsAllowed));
passwordValidator = new PasswordValidator(messageResolver, rules);
validators.put(ValidatorTypes.StandardValidator, passwordValidator);
}
}
use of org.passay.LengthRule in project dataverse by IQSS.
the class PasswordValidatorServiceBean method addGoodStrengthValidator.
/**
* goodStrengthValidator
* <p>
* Apply Rule 4: It will forgo all the above three requirements for passwords that have a minimum length of
* MIN_LENGTH_BIG_LENGTH.
*/
private void addGoodStrengthValidator() {
int goodStrength = getGoodStrength();
if (goodStrength != 0) {
PasswordValidator passwordValidator = validators.get(ValidatorTypes.GoodStrengthValidator);
if (passwordValidator == null) {
final GoodStrengthRule lengthRule = new GoodStrengthRule();
lengthRule.setMinimumLength(goodStrength);
final List<Rule> rules = Collections.singletonList(lengthRule);
passwordValidator = new PasswordValidator(messageResolver, rules);
validators.put(ValidatorTypes.GoodStrengthValidator, passwordValidator);
}
}
}
Aggregations