可能重复:
在命令行上隐藏输入
我正在制作一个密码安全检查程序,我的问题很奇怪,因为我的程序运行得很好.我想知道的是,是否有任何方法可以将输入到控制台的文本显示为在密码字段中显示的内容.即,在用户按下返回键之前,输入的单词将显示为"****".
我知道JFrame有一种JPasswordField方法,但我不认为这只是在使用时帮助我Scanner.
这是我的代码:
import java.util.Scanner;
public class SecurityCheckerMain {
static String enteredPassword;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter your password: ");
enteredPassword = input.nextLine();
Checker tc = new Checker(enteredPassword);
tc.checkSecurity();
}
}
Run Code Online (Sandbox Code Playgroud)
public class Checker {
//number of chars : the Higher the Better("password must be greater than 8 chars"){done}
//combination of uppercase and lowercase{done}
//contains numbers{done}
//non repeated characters (every char is different ascii …Run Code Online (Sandbox Code Playgroud) 我有一个void方法,它应该采用一个String并根据分隔符将其拆分为两个字符串.使用调试器后,该方法似乎正常工作,但我传入的两个空字符串,用于存储结果的方法似乎没有得到更新.我必须在这里做一些愚蠢的事,但任何帮助都表示赞赏!
public static void main(String[] args) {
String dictFile = "/Users/simonrhillary/Desktop/Dictionary(3).txt";
String synFile = "/Users/simonrhillary/Desktop/Synonyms(2).txt";
fileReader dictFR = new fileReader();
fileReader synFR = new fileReader();
dictFR.filePath = dictFile;
synFR.filePath = synFile;
dictFR.openFile(dictFile);
synFR.openFile(synFile);
String[] dictionary = dictFR.fileToArray();
String[] synonyms = synFR.fileToArray();
String regx = "^[aflmptu]+$";
String regexTemplate = "^[]+$";
String word1 = "";
String word2 = "";
synToWords(synFR.getLine(3), word1, word2);//error seems to be here.
//word1 and word 2 stay ""
System.out.println(word1 +" " + word2);
printArray(findCombos(dictionary, word1, word2));
}
public …Run Code Online (Sandbox Code Playgroud)