This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Java in General and the fly likes prevent characters from being desplayed on command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "prevent characters from being desplayed on command" Watch "prevent characters from being desplayed on command" New topic

prevent characters from being desplayed on command

moshi cochem
Ranch Hand

Joined: Nov 10, 2009
Posts: 91
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.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20049

Check out and its readPassword methods. They will not show * characters but absolutely nothing; I'm sure that is enough for security reasons

How To Ask Questions How To Answer Questions
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43368
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.
subject: prevent characters from being desplayed on command
It's not a secret anymore!