2

I'm using Spring Shell for a CLI and I want to read a password from the input line. For such purpose spring shell has jline, so using the official documentation [1] of jline it suggests the following:

public static void main(String[] args) throws IOException {
    String password = new ConsoleReader().readLine('*');
    System.out.println("My password is: "+password);
}

When starting the application it looks like this:

mysecretpassword   << entered by myself 
****************   << masking from jline
My password is: mysecretpassword  << my output

So my question is what is the purpose of masking the password if it is shown anyway, when I type it? Is there a possibility to do it Unix style and don't even show the password, while typing it?

[1] http://jline.sourceforge.net/#installation

Christian Götz
  • 818
  • 1
  • 8
  • 11

2 Answers2

1

While you tagged your question with spring-shell, there is an open issue for support of masked (password) options.

Cengiz
  • 5,375
  • 6
  • 52
  • 77
0

For what it's worth, we implemented this feature directly (bypassing JLine) like so in Spring XD: (see UserInput.prompt()) https://github.com/spring-projects/spring-xd/blob/master/spring-xd-shell/src/main/java/org/springframework/xd/shell/command/ConsoleUserInput.java

ebottard
  • 1,997
  • 2
  • 12
  • 14