public class Login {
protected static String user, pass, host;
Object conn;
public void Login() throws SQLException
{
try {
Class.forName ("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
System.out.println ("Could not load the driver");
}
Scanner sc = new Scanner(System.in);
Console console = System.console();
System.out.println("Please Enter Username");
user = sc.next();
System.out.println("Please Enter Password");
pass = sc.nextLine();
System.out.println("Please Enter Host/IP Address");
host = sc.next();
System.out.println("Attempting Log In");
Connection conn = (Connection) DriverManager.getConnection
("jdbc:mysql://"+host+":3306/chessdb", user, pass);
只是一点帮助,一直在网上寻找阻止密码显示在控制台窗口上的方法。有没有一种简单的方法,要么完全不显示输入的文本,要么用星号仅覆盖密码字段的输入?
最佳答案
使用readPassword()
方法。
而不是像使用扫描仪那样
System.out.println("Please Enter Password");
pass = sc.nextLine();
用途:
System.out.println("Please Enter Password");
char[] passString = Console.readPassword();
String pass = new String(passString );
关于java - 从控制台窗口隐藏密码 Java Asterisk 密码或阻止显示输入的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27050323/