The password is not displayed on the console when you enter a password on the console using the following method: Console Cons=system.console ();
System.out.print ("Please enter password:");
Char[] Pwd=cons.readpassword ();
String password = new string (PWD);
SYSTEM.OUT.PRINTLN (password), as described in the JDK API documentation:
Security Note: If an application needs to read a password or other security data, it should use or, and after execution, manually return the returned character array to zero to minimize the lifetime of sensitive data in memory.
Java.util.Arrays.fill (pwd, "); explain the java.io.Console. This class is a new class library in JDK 6, for the console of the operating system, the console of the system can only be used in the operating system's native console and cannot be used in the IDE's console, because the console in the IDE is redirected. Tested, if this readpassword () is used on eclipse, throw NullPointerException directly
2011-12-27
Java: Enter the password in the DOS window, do not display the password directly, the original can be so simple