- Passay Tutorial
- Passay − Home
- Passay − Overview
- Passay − environment Setup
- Validation/Generation
- Passay − Password Validation
- Passay − Customized Messages
- Passay − M of N Rules
- Passay − Password Generation
- Positive Matching Rules
- passay − AllowedCharacterRule
- Passay − AllowedRegexRule
- Passay −CharacterRule
- passay − LengthRule
- Passay − CharacterCharacteristicsRule
- Passay − LengthComplexityRule
- Negative Matching Rules
- Passay − lllegalCharacterRule
- Passay − NumberRangeRule
- Passay − WhitespaceRule
- Passay − DictionaryRule
- Passay − DictionarySubstringRule
- Passay − HistoryRule
- passay − RepeatCharacterRegexRule
- Passay − usernameRule
- Passay Useful Resources
- Passay - Quick Guide
- Passay - Resources
- Passay - Discussion
Passay - HistoryRule
HistoryRule allows to check if given password has not been in use in near past. Consider the following example.
Example
import org.passay.HistoryRule; import org.passay.PasswordData; import org.passay.PasswordValidator; import org.passay.RuleResult; import org.passay.SourceRule; public class PassayExample { public static void main(String[] args) { SourceRule sourceRule = new SourceRule(); HistoryRule historyRule = new HistoryRule(); PasswordValidator validator = new PasswordValidator(sourceRule, historyRule); PasswordData password = new PasswordData("password@123"); password.setPasswordReferences( new PasswordData.SourceReference("source", "password"), new PasswordData.HistoricalReference("password@123") ); RuleResult result = validator.validate(password); if(result.isValid()){ System.out.println("Password validated."); }else{ System.out.println("Invalid Password: " + validator.getMessages(result)); } } }
Output
Invalid Password: [Password matches one of 1 previous passwords.]
Advertisements