FileDocCategorySizeDatePackage
Password.javaAPI DocExample1996Sat Dec 02 19:43:56 GMT 2000jabadot

Password

public class Password extends Object

Fields Summary
public static final int
MIN_LENGTH
Minimum length for a decent password
protected static Random
r
The random number generator.
protected String
pw
This password's value as a String
protected static char[]
goodChar
Constructors Summary
public Password(String p)
Construct a password using the given String as the "user's pick".

throws
java.lang.IllegalArgumentException If password too short.


	                 	 
	   
		if (p.length() < MIN_LENGTH)
			throw new IllegalArgumentException(
			"Password " + p + " length less than minimum of " + MIN_LENGTH);
		pw = p;
	
public Password()
Construct a password: we pick the password. This constructor is wasteful: you are better off using the static method getNext(), which returns a new Password object.

		pw = getNext().toString();
	
Methods Summary
public static jabadot.PasswordgetNext()


	/* Generate a Password object with a random password. */
	    
		StringBuffer sb = new StringBuffer();
		for (int i=0; i < MIN_LENGTH + 2; i++) {
			sb.append(goodChar[r.nextInt(goodChar.length)]);
		}
		return new Password(sb.toString());
	
public java.lang.StringgetPassword()
Return this Password as a String

		return pw;
	
public static voidmain(java.lang.String[] argv)

		for (int i=0; i<20; i++) {
			System.out.println(Password.getNext());
		}
	
public java.lang.StringtoString()
Return this Password as a String

		return pw;