We can see that each rule gives us a clear explanation if the password is not valid. There are notifications that the password is too short and has two illegal characters. We can also notice that the password doesn't match the provided regular expression.
What's more, we're informed that it contains insufficient lowercase letters.
5.2. CharacterCharacterisitcsRule
CharcterCharacterisitcsRule is more complex than rules presented before. To create a CharcterCharacterisitcsRule object, we need to provide a list of CharacterRules. What's more, we have to set how many of them the password must match. We can do it this way:
CharacterCharacteristicsRule characterCharacteristicsRule = new CharacterCharacteristicsRule(
3,
new CharacterRule(EnglishCharacterData.LowerCase, 5),
new CharacterRule(EnglishCharacterData.UpperCase, 5),
new CharacterRule(EnglishCharacterData.Digit),
new CharacterRule(EnglishCharacterData.Special)
);
Presented CharacterCharacteristicsRule requires a password to contain three of four provided rules.
5.3. LengthComplexityRule
On the other hand, Passay library provides us with LengthComplexityRule. It allows us to define which rules should be applied to the password of which length. In contra st to CharacterCharacteristicsRule, they allow us to use all kind of rules – not only CharacterRule.
Let's analyze the example:
LengthComplexityRule lengthComplexityRule = new LengthComplexityRule();
lengthComplexityRule.addRules("[1,5]", new CharacterRule(EnglishCharacterData.LowerCase, 5));
lengthComplexityRule.addRules("[6,10]",
new AllowedCharacterRule(new char[] { 'a', 'b', 'c', 'd' }));
As we can see for password having one to five characters, we apply CharacterRule. But for a password containing six to ten characters, we want the password to match AllowedCharacterRule.
Do'stlaringiz bilan baham: |