mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
add setting to disable strict password policy (#1059)
This commit is contained in:
@@ -14,8 +14,13 @@ import org.passay.PasswordValidator;
|
||||
import org.passay.RuleResult;
|
||||
import org.passay.WhitespaceRule;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
public class PasswordConstraintValidator implements ConstraintValidator<ValidPassword, String> {
|
||||
|
||||
@Setter
|
||||
private static boolean strict = true;
|
||||
|
||||
@Override
|
||||
public void initialize(ValidPassword constraintAnnotation) {
|
||||
// nothing to do
|
||||
@@ -27,7 +32,7 @@ public class PasswordConstraintValidator implements ConstraintValidator<ValidPas
|
||||
return true;
|
||||
}
|
||||
|
||||
PasswordValidator validator = buildPasswordValidator();
|
||||
PasswordValidator validator = strict ? buildStrictPasswordValidator() : buildLoosePasswordValidator();
|
||||
RuleResult result = validator.validate(new PasswordData(value));
|
||||
|
||||
if (result.isValid()) {
|
||||
@@ -40,10 +45,10 @@ public class PasswordConstraintValidator implements ConstraintValidator<ValidPas
|
||||
return false;
|
||||
}
|
||||
|
||||
private PasswordValidator buildPasswordValidator() {
|
||||
private PasswordValidator buildStrictPasswordValidator() {
|
||||
return new PasswordValidator(
|
||||
// length
|
||||
new LengthRule(8, 128),
|
||||
new LengthRule(8, 256),
|
||||
// 1 uppercase char
|
||||
new CharacterRule(EnglishCharacterData.UpperCase, 1),
|
||||
// 1 lowercase char
|
||||
@@ -56,4 +61,12 @@ public class PasswordConstraintValidator implements ConstraintValidator<ValidPas
|
||||
new WhitespaceRule());
|
||||
}
|
||||
|
||||
private PasswordValidator buildLoosePasswordValidator() {
|
||||
return new PasswordValidator(
|
||||
// length
|
||||
new LengthRule(6, 256),
|
||||
// no whitespace
|
||||
new WhitespaceRule());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user