Masking password input field from console in eclipse java

I used JDK 1.5 to run my code.
Does anyone know a way to mask a password from console input?

I tried using console.readPassword() but it does not work in eclipse environment. A complete example can really help me.

+4
source share
3 answers

This article can be useful if there were no command-line APIs to mask passwords: http://java.sun.com/developer/technicalArticles/Security/pwordmask/

As a side note, wasn't it just the Console class added in Java 1.6? Do you get any errors in Eclipse?

+2
source

Try using swing:

 final String password, message = "Enter password"; if( System.console() == null ) { // inside IDE like Eclipse or NetBeans final JPasswordField pf = new JPasswordField(); password = JOptionPane.showConfirmDialog( null, pf, message, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE ) == JOptionPane.OK_OPTION ? new String( pf.getPassword() ) : ""; } else password = new String( System.console().readPassword( "%s> ", message ) ); 
+1
source

readPassword () uses native code to turn off echo. It probably depends on the platform. So I don’t think you will get a simple pure Java solution. Why not run the program in a real console?

0
source

Source: https://habr.com/ru/post/1383437/


All Articles