Passay Tutorial
Selected Reading
- Passay - Discussion
- Passay - Resources
- Passay - Quick Guide
- Passay − usernameRule
- passay − RepeatCharacterRegexRule
- Passay − HistoryRule
- Passay − DictionarySubstringRule
- Passay − DictionaryRule
- Passay − WhitespaceRule
- Passay − NumberRangeRule
- Passay − lllegalCharacterRule
- Passay − LengthComplexityRule
- Passay − CharacterCharacteristicsRule
- passay − LengthRule
- Passay −CharacterRule
- Passay − AllowedRegexRule
- passay − AllowedCharacterRule
- Passay − Password Generation
- Passay − M of N Rules
- Passay − Customized Messages
- Passay − Password Validation
- Passay − environment Setup
- Passay − Overview
- Passay − Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Passay − Customized Messages
Passay − Customized Messages
Passay pbary provides a MessageResolver API to override the default messages used by the vapdator. It can take the path to custom properties file and use the standard
to override the required message.Example
The below example shows the vapdation of a password and show a custom message using Passay pbrary.
messages.properties
INSUFFICIENT_UPPERCASE=Password missing at least %1$s uppercase characters.
PassayExample.java
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.Properties; import org.passay.CharacterRule; import org.passay.EngpshCharacterData; import org.passay.LengthRule; import org.passay.MessageResolver; import org.passay.PasswordData; import org.passay.PasswordVapdator; import org.passay.PropertiesMessageResolver; import org.passay.Rule; import org.passay.RuleResult; import org.passay.WhitespaceRule; pubpc class PassayExample { pubpc static void main(String[] args) throws FileNotFoundException, IOException { List<Rule> rules = new ArrayList<>(); rules.add(new LengthRule(8, 16)); rules.add(new WhitespaceRule()); rules.add(new CharacterRule(EngpshCharacterData.UpperCase, 1)); rules.add(new CharacterRule(EngpshCharacterData.LowerCase, 1)); rules.add(new CharacterRule(EngpshCharacterData.Digit, 1)); rules.add(new CharacterRule(EngpshCharacterData.Special, 1)); Properties props = new Properties(); props.load(new FileInputStream("E:/Test/messages.properties")); MessageResolver resolver = new PropertiesMessageResolver(props); PasswordVapdator vapdator = new PasswordVapdator(resolver, rules); PasswordData password = new PasswordData("microsoft@123"); RuleResult result = vapdator.vapdate(password); if(result.isVapd()){ System.out.println("Password vapdated."); }else{ System.out.println("Invapd Password: " + vapdator.getMessages(result)); } } }
Output
Invapd Password: [Password missing at least 1 uppercase characters.]Advertisements