PasswordGenerator helps in generating password using given policy. Consider the following policy:
Length of password should be 8 characters.
A password should contains each of the following: upper, lower, digit and a symbol.
The below example shows the generation of a password against above policy using Passay library.
import org.passay.CharacterRule; import org.passay.EnglishCharacterData; import org.passay.PasswordGenerator; public class PassayExample { public static void main(String[] args) { CharacterRule alphabets = new CharacterRule(EnglishCharacterData.Alphabetical); CharacterRule digits = new CharacterRule(EnglishCharacterData.Digit); CharacterRule special = new CharacterRule(EnglishCharacterData.Special); PasswordGenerator passwordGenerator = new PasswordGenerator(); String password = passwordGenerator.generatePassword(8, alphabets, digits, special); System.out.println(password); } }
?\DE~@c3