Passay - HistoireRègle
HistoryRulepermet de vérifier si le mot de passe donné n'a pas été utilisé dans un passé proche. Prenons l'exemple suivant.
Exemple
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("[email protected]");
password.setPasswordReferences(
new PasswordData.SourceReference("source", "password"),
new PasswordData.HistoricalReference("[email protected]")
);
RuleResult result = validator.validate(password);
if(result.isValid()){
System.out.println("Password validated.");
}else{
System.out.println("Invalid Password: " + validator.getMessages(result));
}
}
}
Production
Invalid Password: [Password matches one of 1 previous passwords.]