I have a Java command line application which needs to take a username and password as arguments passed in the main function.
Is there a way to make the password shown as asterisk when the user types their password?
Thanks.
I have a Java command line application which needs to take a username and password as arguments passed in the main function.
Is there a way to make the password shown as asterisk when the user types their password?
Thanks.
There is no way that I know of to pass a hidden password to the main method as a command line argument without some kind of wrapper program.
However, using System.console().readPassword()
or System.console().readPassword(String fmt, Object... args)
the program can read user input from the command line without showing what the user is typing.
Edit: I don't know of any existing thing in java that replaces all the characters in the password with asterisks as the user types them but doing such a thing would require making it so that the command line would send program the characters individually instead of all together at a line ending.
Nothing easy or portable but more information on that here.