• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

prevent characters from being desplayed on command

 
moshi cochem
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I run a program in command, and I want the user to type password without being seen -
I want '******' instead of the real letters.
How can I do it when I run my class in windows command ? It is not swing, only simple j2se class.
I saw an example that runs another thread that fills the command with blank spaces or with stars... but
it is not elegant as typing '*****' instead of the real characters.
Maybe it is imposible, but if there is a way I'll be glad to hear.
Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out java.io.Console and its readPassword methods. They will not show * characters but absolutely nothing; I'm sure that is enough for security reasons
 
Campbell Ritchie
Sheriff
Pie
Posts: 49793
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Console will work, but you need a fallback. If you use javaw or similar to start the application, the Console will be null, so you get Exceptions. In that case you would have to us other entry types, eg JOptionPane, JPasswordField.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic