在控制台窗口中隐藏密码输入

时间:2016-11-15 19:31:50

标签: java passwords hidden

当我输入我的密码到控制台窗口时,它是可见的,无论如何这可以改变,以便它不可见?这是我的代码:

    String user, pass, host;

    Scanner sc = new Scanner(System.in);
    System.out.println("Type userid, password, hostname or ipaddress: ");
    user = sc.next();
    pass = sc.next();
    host = sc.next();
    System.out.println(user + " " + pass + " " + host);
    Methods md = new Methods();
    md.createTable(user, pass, host);

1 个答案:

答案 0 :(得分:0)

使用Console readPassword()方法:

 char[] passwd = System.console().readPassword("[%s]", "Password:");