File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
Author

prevent characters from being desplayed on command

moshi cochem
Ranch Hand

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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38881
    
  23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: prevent characters from being desplayed on command