public final class PasswordGenerator
extends java.lang.Object
PasswordGenerator
allows the user
to choose the character sets, by using bitmasks created from the following constants:
USE_CHARS_LOWER
stands for including lower characters.
USE_CHARS_UPPER
stands for including upper characters.
USE_NUMBERS
stands for including digits.
USE_SPECIAL_BASIC
stands for including characters such as ".-_".
USE_SPECIAL_EXTENDED
stands for including characters such as "!\"$%&/()=?{[]}\\`*+~#'^<>'".
PasswordGenerator gen = new PasswordGenerator();
String password = gen.generate(20, USE_CHARS_LOWER | USE_CHARS_UPPER | USE_SPECIAL_BASIC);
This creates a password of length 20 consisting of lower characters, upper characters as well as characters of the set ".-_".
PasswordStrengthChecker
Modifier and Type | Field and Description |
---|---|
static int |
USE_ALL
Use lower, upper, special and extended special characters plus numbers.
|
static int |
USE_CHARS_LOWER
Use lower case characters.
|
static int |
USE_CHARS_UPPER
Use upper case characters.
|
static int |
USE_NUMBERS
Use numbers.
|
static int |
USE_SPECIAL_BASIC
Use basic special characters.
|
static int |
USE_SPECIAL_EXTENDED
Use extended special characters.
|
Constructor and Description |
---|
PasswordGenerator()
Instantiates a new password generator.
|
PasswordGenerator(java.security.SecureRandom random)
Instantiates a new password generator.
|
Modifier and Type | Method and Description |
---|---|
char[] |
generate(int length)
Generate a random password using all available characters.
|
char[] |
generate(int length,
int usedSymbolMask)
Generate a random password.
|
char[] |
generate(int length,
int usedSymbolMask,
java.lang.String additionalChars)
Generate a random password.
|
char[] |
generateCharOnly(int length)
Generate a random password using lower and upper case characters only.
|
char[] |
generateNumberOnly(int length)
Generate a random password containing numbers only.
|
public static final int USE_CHARS_LOWER
public static final int USE_CHARS_UPPER
public static final int USE_NUMBERS
public static final int USE_SPECIAL_BASIC
public static final int USE_SPECIAL_EXTENDED
public static final int USE_ALL
public PasswordGenerator(java.security.SecureRandom random)
random
- the PRNG to be usedpublic PasswordGenerator()
public char[] generate(int length, int usedSymbolMask, java.lang.String additionalChars)
length
- the length of the passwordusedSymbolMask
- the used symbolsadditionalChars
- additional characters to be includedpublic char[] generate(int length, int usedSymbolMask)
length
- the length of the passwordusedSymbolMask
- the used symbolspublic char[] generate(int length)
length
- the length of the passwordpublic char[] generateCharOnly(int length)
length
- the length of the passwordpublic char[] generateNumberOnly(int length)
length
- the length of the password