org.PingOO.DLAI.lib.util
Class PasswordGenerator

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.util.PasswordGenerator

public final class PasswordGenerator
extends java.lang.Object

This class can randomly generate a password, a salt and crypt the password using the UNIX crypt algorithm.

Since:
PingOO 2.0
Version:
2.0
Author:
Sébastien Delcroix (seb@cur-archamps.fr), Jean-François Giraud (jf@cur-archamps.fr), Fabrice Bouyé (bouye@cur-archamps.fr)
See Also:
PasswordCodec

Field Summary
static int DEFAULT_PASSWORD_LENGTH
          Default password lenght.
static int DEFAULT_SALT_LENGTH
          Default password lenght.
private static java.util.Random random
          The random number generator.
private static int seed
          The random seed.
 
Constructor Summary
private PasswordGenerator()
          Hiddes the constructor from the outside.
 
Method Summary
static java.lang.String cryptPassword(java.lang.String password)
          Crypts a password, using the UNIX crypt algorithm and a randomly generated salt.
static java.lang.String cryptPassword(java.lang.String password, java.lang.String salt)
          Crypts a password, using the UNIX crypt algorithm and the provided salt.
static java.lang.String generatePassword()
          Randomly generates a eight letters long password.
static java.lang.String generatePassword(int passwordLength)
          Randomly generates a password.
static java.lang.String generateSalt()
          Randomly generates a two letters long salt.
private static void initialize()
          Initialize the number generator.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEFAULT_PASSWORD_LENGTH

public static final int DEFAULT_PASSWORD_LENGTH
Default password lenght.

DEFAULT_SALT_LENGTH

public static final int DEFAULT_SALT_LENGTH
Default password lenght.

seed

private static int seed
The random seed.

random

private static java.util.Random random
The random number generator.
Constructor Detail

PasswordGenerator

private PasswordGenerator()
Hiddes the constructor from the outside.
Method Detail

cryptPassword

public static final java.lang.String cryptPassword(java.lang.String password)
Crypts a password, using the UNIX crypt algorithm and a randomly generated salt.
Parameters:
password - The non-crypted password.
Returns:
The crypted password. The two first letters are the salt.

cryptPassword

public static final java.lang.String cryptPassword(java.lang.String password,
                                                   java.lang.String salt)
Crypts a password, using the UNIX crypt algorithm and the provided salt.
Parameters:
password - The non-crypted password.
password - The salt needed to crypt the password.
Returns:
The crypted password. The two first letters are the salt.

generateSalt

public static final java.lang.String generateSalt()
Randomly generates a two letters long salt.
Returns:
A generated a two letters long salt.

generatePassword

public static final java.lang.String generatePassword()
Randomly generates a eight letters long password.
Returns:
The generated eight letters long password.

generatePassword

public static final java.lang.String generatePassword(int passwordLength)
Randomly generates a password.
Parameters:
passwordLength - The desired lenght of the password. If passwordLength < 8, the password will be at least 8 letters long.
Returns:
The generated password.

initialize

private static final void initialize()
Initialize the number generator.