Этот код работает, но у меня мало проблем < /p>
Создание работает, но здесь нет никаких признаков, когда я печатаю. Когда я введу неправильный пароль и нажимаю введите, он скажет неправильный пароль, и если мой пароль и учетные данные правы, он продолжит < /li>
Мне нужно нажать 2x Enter, чтобы продолжить < /li>
< /ol>
client.java>
public static void main(String[] args) {
try (Socket socket = new Socket(SERVER, PORT);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
Scanner scanner = new Scanner(System.in);) {
Thread readerThread = new Thread(() -> {
try {
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
if (line.trim().toLowerCase().startsWith("enter password")) {
Console console = System.console();
String password;
if (console != null) {
char[] passwordChars = console.readPassword();
password = new String(passwordChars);
continue; // here is fix for register issue on y/n question
} else {
System.out.print("(No masking) Enter password: ");
password = scanner.nextLine();
out.println(password);
}
out.println(password);
}
}
}
catch (IOException e) {
System.out.println("Connection error in reader thread.");
}
});
readerThread.start();
while (true) {
if (scanner.hasNextLine()) {
String input = scanner.nextLine();
out.println(input);
}
}
} catch (IOException e) {
System.out.println("Unable to connect to server.");
}
}
< /code>
login.java
for (int attempts = 0; attempts < 3; attempts++) {
out.println("Enter password:");
out.flush();
String password = in.readLine();
if (password == null) return null
< /code>
register.java
out.println("Enter password:");
out.flush();
password = in.readLine();
if (password == null) return;
if (password.matches("^\\S{8,}$")) {
break;
} else {
out.println("+------------------------------------+");
out.println("| Invalid password. Try again. |");
out.println("+------------------------------------+");
out.flush();
}
break;
}
String Password = password;
// Admin or User decision loop
String response;
while (true) {
out.println("Are you registering as an admin? (y/n):");
out.flush();
response = in.readLine();
< /code>
Вопросы < /h3>
Как это будет "*" вместо пустых.
Почему мне нужно нажать введите 2x после того, как пароль маски будет исправлено, чтобы один
event < /p>
Подробнее здесь: https://stackoverflow.com/questions/796 ... rd-in-java
CLI Socket Thread Masking of Password в Java ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Socket IO Java Android App и Socket IO JavaScript Server Достоверное подключение?
Anonymous » » в форуме Android - 0 Ответы
- 7 Просмотры
-
Последнее сообщение Anonymous
-