0

is there any way to display •••'s when a user is typing in the console? My program has a user entering a password for a MySQL database but I want it to show •••'s instead of their password when they type.

Steffen
  • 1
  • 1
  • 1
  • You have no direct control of the console, to the Java process it's just an input stream. If you want asterisks, you'll have to upgrade to a GUI interface. – Marko Topolnik Sep 13 '16 at 16:54

2 Answers2

2

You can use Console.readPassword() to disable echoing. I don't think there's any way to get a substitute character without JNI though.

markspace
  • 10,621
  • 3
  • 25
  • 39
-1

Dont know about showing "." But instead you can use

char[] password = console.readPassword("Password? ");

to input password without echoing on screen.

Community
  • 1
  • 1
Nik
  • 1
  • 2