我正在将 Spring Shell 用于 CLI,并且我想从输入行读取密码。为此,spring shell 具有 jline,因此使用 jline 的官方文档 [1] 建议如下:
public static void main(String[] args) throws IOException {
String password = new ConsoleReader().readLine('*');
System.out.println("My password is: "+password);
}
启动应用程序时,它看起来像这样:
mysecretpassword << entered by myself
**************** << masking from jline
My password is: mysecretpassword << my output
所以我的问题是,当我输入密码时,如果密码仍然显示,隐藏密码的目的是什么?是否有可能在输入时使用 Unix 风格并且甚至不显示密码?