Passay 简明教程
Passay - Password Generation
PasswordGenerator 有助于根据给定的策略生成密码。考虑以下策略:
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.
Example
以下示例显示了如何使用Passay库根据上述策略生成密码。
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);
}
}