本文介紹了利用掃描儀實(shí)現(xiàn)Java中的口令屏蔽的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我是一名學(xué)習(xí)Java的高中生,我想知道如何在Scanner中自動(dòng)將輸入文本更改為星號(hào)。這是我為一個(gè)項(xiàng)目做的一個(gè)簡(jiǎn)單的登錄系統(tǒng)。我的代碼是
Scanner scan = new Scanner(System.in);
boolean correctLogin = false;
String username;
String password;
String enteredUsername;
String enteredPassword;
while(correctLogin != true){
System.out.println("Enter Username: ");
enteredUsername = scan.nextLine();
System.out.println("Enter Password: ");
enteredPassword = scan.nextLine();
if(enteredUsername.equals("username") && enteredPassword.equals("passw00rd")){
System.out.println("You have entered the correct login info");
correctLogin = true;
break;
}
else{
System.out.println("Your login info was incorrect, please try again");
}
}
System.out.println("You are now logged in, good job!");
我想要它,以便在我鍵入密碼時(shí),它會(huì)自動(dòng)變?yōu)樾翘?hào)。
推薦答案
嘗試此密碼讀取:
Console console = System.console();
if(console != null){
console.readPassword("Enter Password: ");
}
這篇關(guān)于利用掃描儀實(shí)現(xiàn)Java中的口令屏蔽的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,






