Java: Enter the password in the DOS window, do not display the password directly, the original can be so simple

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.