File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .io .Console ;
2+ import java .io .IOError ;
3+
4+ public class Login {
5+ public static void main (String [] args ) {
6+ Console console = System .console ();
7+ if (console == null ){
8+ System .err .println ("no console device is present." );
9+ return ;
10+ }
11+ try {
12+ String username = console .readLine ("Username: " );
13+ char [] pwd = console .readPassword ("Password: " );
14+ // Do something useful with the username and password, this application just prints them out for demonstration.
15+ System .out .println ("demo_username: " + username );
16+ System .out .println ("demo_password: " + new String (pwd ));
17+ // Prepare username for garbage collection.
18+ // More importantly, destroy the password by zeroing out the char array.
19+ username = "" ;
20+ for (int i =0 ;i <pwd .length ;i ++){
21+ pwd [i ] = 0 ;
22+ }
23+ }catch (IOError ioe ){
24+ ioe .printStackTrace ();
25+ }
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments