Rakesh API

org.rakeshv.utils
Class PasswordGenerator

java.lang.Object
  extended by org.rakeshv.utils.PasswordGenerator

public final class PasswordGenerator
extends java.lang.Object

A utility class that can be used to generate secure random password values.

Copyright 2005-2006 Rakesh Vidyadharan

Since:
1.17
Version:
$Id: PasswordGenerator.java,v 1.3 2006/03/11 04:15:14 rakesh Exp $
Author:
Rakesh Vidyadharan 2005 August 25

Field Summary
private static char[] PASSWORD_CHARACTERS
          The default characters that are allowed in a password value.
private static java.security.SecureRandom random
          The random number generator.
 
Constructor Summary
private PasswordGenerator()
          Default constructor.
 
Method Summary
private static int byteToInt(byte byteValue)
          Convert a byte value into a postive integer.
static char[] generatePassword(int length)
          Generate a random password of the specified length.
static char[] generatePassword(int length, char[] characters)
          Generate a random password of the specified length and restricted to the characters specified.
private static int getIntFromByte(byte[] bytes)
          Convert a byte value returned by the random number generator (random) to an integer that may be used to index into the allowable characters array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PASSWORD_CHARACTERS

private static final char[] PASSWORD_CHARACTERS
The default characters that are allowed in a password value.


random

private static final java.security.SecureRandom random
The random number generator.

Constructor Detail

PasswordGenerator

private PasswordGenerator()
Default constructor. Cannot be instantiated.

Method Detail

generatePassword

public static final char[] generatePassword(int length)
Generate a random password of the specified length.

Parameters:
length - The desired length of the password.
Returns:
char[] The array of characters that comprise the random password.
See Also:
generatePassword( int, char[] )

generatePassword

public static final char[] generatePassword(int length,
                                            char[] characters)
Generate a random password of the specified length and restricted to the characters specified.

Parameters:
length - The desired length of the password.
characters - The array of valid characters thay may be used in the password.
Returns:
char[] The array of characters that comprise the random password.

getIntFromByte

private static final int getIntFromByte(byte[] bytes)
Convert a byte value returned by the random number generator (random) to an integer that may be used to index into the allowable characters array.

Parameters:
bytes - The byte values returned by the random number generator.

byteToInt

private static final int byteToInt(byte byteValue)
Convert a byte value into a postive integer.

Parameters:
byteValue - The byte that is to be converted into an integer.
Returns:
int The converted positive value.

Rakesh API

Copyright © 2002-2005 - Rakesh Vidyadharan