1 7 package org.jboss.security.plugins; 8 9 import java.io.IOException ; 10 import java.io.CharArrayWriter ; 11 12 20 public class ConsolePassword 21 { 22 public ConsolePassword() 23 { 24 } 25 26 public char[] toCharArray() 27 throws IOException 28 { 29 System.err.print("Enter password: "); 30 CharArrayWriter writer = new CharArrayWriter (); 31 int b; 32 while( (b = System.in.read()) >= 0 ) 33 { 34 if( b == '\r' || b == '\n' ) 35 break; 36 writer.write(b); 37 } 38 char[] password = writer.toCharArray(); 39 writer.reset(); 40 for(int n = 0; n < password.length; n ++) 41 writer.write('\0'); 42 return password; 43 } 44 45 public static void main(String [] args) throws IOException 46 { 47 ConsolePassword cp = new ConsolePassword(); 48 System.out.println(new String (cp.toCharArray())); 49 } 50 } 51 | Popular Tags |