1

I am trying to run a java application in console. Here is the code for username and password I used console.readPassword() and when I type my password in the console the cursor appears on the same same starting line and it remains in the same position until I enter the full password and click on Enter button.

    Console console = System.console();
    console.printf("Please enter your username: ");
    String username = console.readLine();
    console.printf(username + "\n");
    console.printf("Please enter your password: ");


    char[] passwordChars = console.readPassword();
    console.printf("Password entered was: %s%n", new String("#####"));
    String password = new String(passwordChars);

This code masks the password after the complete password is entered, but it does not show any cursor movements when the user enters their password.

My idea would be something like masking the password with special characters and the proper cursor movements which does not confuse the user. Can someone help me with this?

Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34
D V
  • 211
  • 6
  • 13

0 Answers0