public class SyntaxRulesPasswordStrengthPolicy extends Object implements PasswordStrengthPolicy
SyntaxRulesPasswordStrengthPolicy policy = SyntaxRulesPasswordStrengthPolicy.create()
.withRule(StandardSyntaxRules.length(8, 4.0))
.withRule(StandardSyntaxRules.characterClasses(3, 2.0))
.withRule(StandardSyntaxRules.upperCaseLetters(1.0))
.withRule(StandardSyntaxRules.lowerCaseLetters(1.0))
.withRule(StandardSyntaxRules.digits(4.0))
.withRule(StandardSyntaxRules.moreCommonSpecialChars(4.0))
.withRule(StandardSyntaxRules.lessCommonSpecialChars(8.0))
.withRule(StandardSyntaxRules.midDigits(2.0))
.withRule(StandardSyntaxRules.midMoreCommonSpecialChars(2.0))
.withRule(StandardSyntaxRules.midLessCommonSpecialChars(2.0))
.withRule(StandardSyntaxRules.lettersOnly(-1.0))
.withRule(StandardSyntaxRules.digitsOnly(-1.0))
.withRule(StandardSyntaxRules.consecutiveUpperCaseLetters(-2.0))
.withRule(StandardSyntaxRules.consecutiveLowerCaseLetters(-2.0))
.withRule(StandardSyntaxRules.consecutiveDigits(-2.0))
.withRule(StandardSyntaxRules.sequentialLetters(3, -3.0))
.withRule(StandardSyntaxRules.sequentialDigits(3, -3.0))
.withRule(StandardSyntaxRules.sequentialSpecialChars(3, -3.0))
.withMinScore(60);
if (!policy.test(password)) {
// Reject password
}
| Constructor and Description |
|---|
SyntaxRulesPasswordStrengthPolicy() |
| Modifier and Type | Method and Description |
|---|---|
SyntaxRulesPasswordStrengthPolicy |
create()
Returns an empty character classes password policy.
|
boolean |
test(char[] password)
Test whether the given password satisfies this strength policy.
|
SyntaxRulesPasswordStrengthPolicy |
withMinScore(double minScore)
Sets the minimum score of this policy.
|
SyntaxRulesPasswordStrengthPolicy |
withRule(ToDoubleFunction<char[]> rule)
Adds the given rule to this policy.
|
public SyntaxRulesPasswordStrengthPolicy create()
public boolean test(char[] password)
PasswordStrengthPolicytest in interface Predicate<char[]>test in interface PasswordStrengthPolicypublic SyntaxRulesPasswordStrengthPolicy withMinScore(double minScore)
new - IllegalArgumentException if minScore is negativepublic SyntaxRulesPasswordStrengthPolicy withRule(ToDoubleFunction<char[]> rule)
new - IllegalArgumentException if minLength is negative