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星号密码或显示的阻止输入的字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27050323/