SPT Core API

com.sptci.util
Class PasswordGenerator

java.lang.Object
  extended by com.sptci.util.PasswordGenerator

public class PasswordGenerator
extends Object

A utility class that can be used to generate secure random password values. Also contains methods to check the quality of a password.

Copyright 2005 Sans Pareil Technologies, Inc.

Version:
$Id: PasswordGenerator.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2005 August 25

Constructor Summary
PasswordGenerator()
          Default constructor.
 
Method Summary
protected  int byteToInt(byte byteValue)
          Convert a byte value into a postive integer.
 boolean checkComplex(char[] password)
          Check the specified password value for quality.
 boolean checkSimple(char[] password)
          Check the specified password value for quality using simple rules.
 char[] generate(int length)
          Generate a random password of the specified length.
 char[] generate(int length, char[] characters)
          Generate a random password of the specified length and restricted to the characters specified.
protected  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
 

Constructor Detail

PasswordGenerator

public PasswordGenerator()
Default constructor. No special actions required.

Method Detail

generate

public char[] generate(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:
generate( int, char[] )

generate

public char[] generate(int length,
                       char[] characters)
Generate a random password of the specified length and restricted to the characters specified. Checks the generated value against checkSimple(char[]) and to ensure that the generated value is good enough.

Note: There is a possibility that this method can go into an infinite loop. This can happen if the characters array contains only those characters that make checkComplex(char[]) always return false.

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.
See Also:
checkComplex(char[])

checkSimple

public boolean checkSimple(char[] password)
Check the specified password value for quality using simple rules. The following rules are used:
  1. Have at least 6 characters.
  2. Have at least 2 alphabetical characters.
  3. Have at least 2 non-alphabetical characters.

Parameters:
password - The password that is to be checked.
Returns:
Returns true if the specified password satisfies the requirements.
See Also:
checkComplex(char[])

checkComplex

public boolean checkComplex(char[] password)
Check the specified password value for quality. The following rules are used:
  1. Have at least 6 characters.
  2. Have at least 2 alphabetical characters.
  3. Have at least 1 numeric characters.
  4. Have at least 1 upper case character.
  5. Have at least 1 lower case character.
  6. Have at least 1 non-alphanumeric character.

Note: There is no guarantee that the password generated by the generate( int, char[] ) method will satisfy these rules.

Parameters:
password - The password that is to be checked.
Returns:
Returns true if the specified password satisfies the requirements.
See Also:
checkSimple(char[])

getIntFromByte

protected 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.
Returns:
The integer value.

byteToInt

protected 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.

SPT Core API