0

I would like to use USER/user as a username and password for my project but i don't know on how to make the password appear as * or • when typing..

Here's my code

String username,password;
int x=0;

do{
 System.out.print("Enter Username: ");
 username=br.readLine();
 System.out.print("Enter Password: "); 
 password=br.readLine();     
 System.out.print("  ");        

 if (username.equalsIgnoreCase("user")&&password.equalsIgnoreCase("user"))
 {x=x+2;}

else
 { System.out.println("     ");         
    System.out.println("WRONG USERNAME OR PASSWORD");}  
  System.out.println("     ");  

I would like the output to be:

Enter Username: user
Enter Password: ••••
leimelson06
  • 39
  • 2
  • 4
  • 12
  • 2
    Look at [Console.readPassword()](http://docs.oracle.com/javase/7/docs/api/java/io/Console.html#readPassword%28%29) – markspace Oct 05 '14 at 01:27
  • Possible duplicate of [String to asterisk, masking password](http://stackoverflow.com/questions/7687600/string-to-asterisk-masking-password). – jww Oct 05 '14 at 03:08

1 Answers1

-2

If you want to read your password in asterisk from the console than you can try this, this will work only with Console -

 Console console = System.console();

 username = console.readLine("Enter Username: ");

 char[] passwordArray = console.readPassword("Enter Password: ");

 password =  new String(passwordArray);

and rest of your logic.

Moni
  • 433
  • 3
  • 9