Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Scanner to read silently from STDIN in Java?

I want to make a Java program that reads a Password from STDIN silently. I mean, without outputting any pressed chars to the terminal and keeping it hidden from commandline history and the operating system processlist ps.

like image 398
rfgamaral Avatar asked May 23 '10 20:05

rfgamaral


1 Answers

The class java.io.Console may be useful:

System.console().readPassword();

This reads a sequence of chars from the console, without echoing anything. Note that it only works when you launch your java application with a real console. Otherwise, System.console() returns null.

like image 101
Eyal Schneider Avatar answered Sep 29 '22 01:09

Eyal Schneider