|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.atlassian.crowd.integration.authentication.PasswordGenerator
public class PasswordGenerator
Generates a random String using a cryptographically secure random number generator.
The alphabet (characters used in the passwords generated) may be specified, and the random number generator can be externally supplied. Care should be taken when using methods that limit the types of passwords may be generated. Using an alphabet that is too small, using passwords that are too short, requiring too many of a certain type of character, or not allowing repetition, may decrease identity. More information about this class is available from ostermiller.org. This class has been modified to no longer use List rather than Vectors.
Field Summary | |
---|---|
protected char[] |
alphabet
Set of characters which may be used in the generated passwords. |
protected char[] |
firstAlphabet
Set of characters which may be used for the first character in the generated passwords. |
protected char[] |
lastAlphabet
Set of characters which may be used for the last character in the generated passwords. |
static char[] |
LETTERS_ALPHABET
Alphabet consisting of upper and lowercase letters A-Z. |
static char[] |
LOWERCASE_LETTERS_ALPHABET
Alphabet consisting of the lowercase letters A-Z. |
static char[] |
LOWERCASE_LETTERS_AND_NUMBERS_ALPHABET
Alphabet consisting of the lowercase letters A-Z and the digits 0-9. |
static char[] |
NONCONFUSING_ALPHABET
Alphabet consisting of upper and lowercase letters A-Z and the digits 0-9 but with characters that are often mistaken for each other when typed removed. |
static char[] |
NUMBERS_AND_LETTERS_ALPHABET
Alphabet consisting of upper and lowercase letters A-Z and the digits 0-9. |
static char[] |
PRINTABLE_ALPHABET
Alphabet consisting of all the printable ASCII characters. |
protected SecureRandom |
rand
Random number generator used. |
protected int |
repetition
One less than the maximum number of repeated characters that are allowed in a password. |
static char[] |
SYMBOLS_ALPHABET
Alphabet consisting of all the printable ASCII symbols. |
static char[] |
UPPERCASE_LETTERS_ALPHABET
Alphabet consisting of the upper letters A-Z. |
static String |
version
Version number of this program. |
Constructor Summary | |
---|---|
PasswordGenerator()
Create a new random password generator with the default secure random number generator and default NONCONFUSING alphabet for all characters. |
|
PasswordGenerator(char[] alphabet)
Create a new random password generator with the default secure random number generator and given alphabet for all characters. |
|
PasswordGenerator(SecureRandom rand)
Create a new random password generator with the given secure random number generator and default NONCONFUSING alphabet for all characters. |
|
PasswordGenerator(SecureRandom rand,
char[] alphabet)
Create a new random password generator with the given secure random number generator and given alphabet for all characters. |
Method Summary | |
---|---|
void |
addRequirement(char[] alphabet,
int num)
Require that a certain number of characters from an alphabet be present in generated passwords. |
String |
getPass()
Generate a random password of the default length (8). |
String |
getPass(int length)
Generate a random password of the given length. |
char[] |
getPassChars()
Generate a random password of the default length (8). |
char[] |
getPassChars(char[] pass)
Fill the given buffer with random characters. |
char[] |
getPassChars(int length)
Generate a random password of the given length. |
void |
setAlphabet(char[] alphabet)
Set the alphabet used by this random password generator. |
void |
setFirstAlphabet(char[] alphabet)
Set the alphabet used by this random password generator for the first character of passwords. |
void |
setLastAlphabet(char[] alphabet)
Set the alphabet used by this random password generator for the last character of passwords. |
void |
setMaxRepetition(int rep)
Set the maximum number of characters that may appear in sequence more than once in a password. |
void |
setRandomGenerator(SecureRandom rand)
Set the random number generator used by this random password generator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String version
public static final char[] NUMBERS_AND_LETTERS_ALPHABET
public static final char[] SYMBOLS_ALPHABET
public static final char[] PRINTABLE_ALPHABET
public static final char[] LOWERCASE_LETTERS_ALPHABET
public static final char[] LOWERCASE_LETTERS_AND_NUMBERS_ALPHABET
public static final char[] LETTERS_ALPHABET
public static final char[] UPPERCASE_LETTERS_ALPHABET
public static final char[] NONCONFUSING_ALPHABET
protected SecureRandom rand
protected int repetition
protected char[] alphabet
protected char[] firstAlphabet
protected char[] lastAlphabet
Constructor Detail |
---|
public PasswordGenerator()
public PasswordGenerator(SecureRandom rand)
rand
- Secure random number generator to use when generating passwords.public PasswordGenerator(char[] alphabet)
alphabet
- Characters allowed in generated passwords.public PasswordGenerator(SecureRandom rand, char[] alphabet)
rand
- Secure random number generator to use when generating passwords.alphabet
- Characters allowed in generated passwords.Method Detail |
---|
public void addRequirement(char[] alphabet, int num)
alphabet
- set of letters that must be presentnum
- number of letters from the alphabet that must be present.public void setAlphabet(char[] alphabet)
alphabet
- Characters allowed in generated passwords.
NullPointerException
- if the alphabet is null.
ArrayIndexOutOfBoundsException
- if the alphabet has no elements.public void setRandomGenerator(SecureRandom rand)
rand
- Secure random number generator to use when generating passwords.public void setFirstAlphabet(char[] alphabet)
alphabet
- Characters allowed for the first character of the passwords.public void setLastAlphabet(char[] alphabet)
alphabet
- Characters allowed for the last character of the passwords.public void setMaxRepetition(int rep)
rep
- Maximum character repetition.public char[] getPassChars(char[] pass)
pass
- buffer that will hold the password.
public char[] getPassChars(int length)
length
- The desired length of the generated password.
public char[] getPassChars()
public String getPass(int length)
length
- The desired length of the generated password.
getPassChars(int)
public String getPass()
getPassChars()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |