nl.nikhef.slcshttps.util
Class PasswordReader

java.lang.Object
  extended by nl.nikhef.slcshttps.util.PasswordReader
All Implemented Interfaces:
Runnable

public class PasswordReader
extends Object
implements Runnable

PasswordReader reads a password and masks the typed inputs, only needed when we use JDK1.5, for 1.6 use java.io.Console.readPassword(). Taken over from Valery Tschopp's org.glite.slcs.ui package, removing main() method. See also the article: Password Masking in the Java Programming Language.

Version:
Revision: 1.2
Author:
Valery Tschopp , Mischa Sallé
See Also:
ConsoleTools.getPassword(String)

Field Summary
private  char echochar
          Character to use for masking.
private  boolean masking
          Indicate whether characters are masked.
 
Constructor Summary
private PasswordReader(String prompt)
          Constructs a PasswordReader using the given prompt.
 
Method Summary
static char[] getPassword(InputStream in, String prompt)
          Obtains a password from given InputStream.
 void run()
          Begin masking until asked to stop.
private  void setEchoChar(char c)
          Sets the char to replace input (mask).
private  void stopMasking()
          Instruct the thread to stop masking.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

masking

private volatile boolean masking
Indicate whether characters are masked.


echochar

private char echochar
Character to use for masking.

Constructor Detail

PasswordReader

private PasswordReader(String prompt)
Constructs a PasswordReader using the given prompt.

Parameters:
prompt - String displayed to the user.
Method Detail

getPassword

public static final char[] getPassword(InputStream in,
                                       String prompt)
                                throws IOException
Obtains a password from given InputStream.

Parameters:
in - InputStream to read from
prompt - String to print first
Returns:
char[] containing the password
Throws:
IOException - upon error

run

public void run()
Begin masking until asked to stop.

Specified by:
run in interface Runnable

stopMasking

private void stopMasking()
Instruct the thread to stop masking.


setEchoChar

private void setEchoChar(char c)
Sets the char to replace input (mask).

Parameters:
c - character for masking.


nl.nikhef.slcshttps Mischa Sallé - msalle(AT)nikhef.nl