Masking a password with the Console class : Console « JDK 6 « Java






Masking a password with the Console class

 
import java.io.Console;

public class Main {

  public static void main(String[] args) {
    Console console = System.console();

    char passwordArray[] = console.readPassword("Enter your secret password: ");
    console.printf("Password entered was: %s%n", new String(passwordArray));
  }
}

   
  








Related examples in the same category

1.Java Console readLine
2.Password Prompting with java.io.Console
3.Console read Password
4.Console output with format
5.Printing text with the Console class
6.Use Console class to read user input?