How To Accept Password From Console in Java Come accettare la password da console in Java
Finally you can easily accept password from console in Java, without echoing them. Infine si può facilmente accettare la password da console in Java, senza eco.
This long unmet need has been addressed in Questo lungo insoddisfatta necessità è stata affrontata in JDK 1.6 JDK 1,6 codeline.
A new class - Una nuova classe -- java.io.Console has been defined to handle console I/O. è stato definito per gestire la console di I / O.
To accept password from console in Per accettare la password da console in JDK 6.0 (aka JDK 1.6) JDK 6.0 (aka JDK 1.6) use either: utilizzare uno:
public char[] readPassword() pubblico char [] readPassword ()
or o
public char[] readPassword(String fmt, Object… args) pubblico char [] readPassword (String fmt, Oggetto… args)
Sample code: Console cons; char[] passwd; if ((cons = System.console()) != null && (passwd = cons.readPassword(”[%s]“, “Password:”)) != null) { // Use the passwd for authentication etc. ….; // Your code // After you are done zero the character array in memory for reducing security risk java.util.Arrays.fill(passwd, ‘ ‘); } Codice di esempio: contro Console; char [] passwd; if ((CONS = System.console ())! = Null & & (passwd = cons.readPassword ( "[% s]", "Password:"))! = Null) (/ / Utilizzare la passwd per l'autenticazione, ecc….; / / Il codice / / Dopo aver finito di zero di caratteri in memoria per la riduzione dei rischi di sicurezza java.util.Arrays.fill (passwd, '');) So could I entice you yet to Così mi invitano ancora download JDK 1.6 scaricare JDK 1,6 ?
Filed under Elencato sotto Headline News Headline News , How To Come , Java Software Software Java , Tech Note Nota tech | |
| |
RSS 2.0 RSS 2,0 | |
Email this Article Invia questo articolo
You may also like to read Si può anche leggere come |





January 12th, 2006 at 10:45 am 12 gennaio 2006 alle 10:45 am
[...] India Fourth Largest Internet User How To Accept Password From Console in Java » JDK1.6 / JDK 6.0 Downloaded? [...] India quarta più grande utente di Internet come ad accettare la password da console in Java »JDK1.6 / JDK 6,0 scaricato? January 12th, 2006 by AngsumanChakraborty [...] 12 gennaio 2006 di AngsumanChakraborty [...]
June 8th, 2006 at 6:21 am 8 giugno 2006 alle 6:21 am
thanks for the service you provided to me. grazie per il servizio che ci hai fornito per me.
November 19th, 2007 at 7:46 pm 19 Novembre 2007 alle 7:46 pm
Console c = System.console(); Console System.console c = ();
if(c != null){ if (c! = null) (
String user = new String(c.readLine(”Enter user:”)); Stringa user = new String (c.readLine ( "Inserisci utente :"));
String pwd = new String(c.readPassword(”Enter pwd:”)); Stringa pwd = new String (c.readPassword ( "Enter pwd :"));
c.printf(”%20s”,user); c.printf ( "% 20s", utente);
c.printf(”\n%20s\n”,pwd); c.printf ( "\ n% 20s \ n", pwd);
}else ) else
System.out.println(”Console is unavailable”); System.out.println ( "Console non è disponibile");
注意運行環境為:jdk1.6+jcreator3.5.注意运行环境为: jdk1.6 + jcreator3.5.
如果jcreator4.0的話,得到的c總是null.如果jcreator4.0的话,得到的c总是nullo.
March 28th, 2008 at 6:46 am 28 marzo, 2008 6:46 am
it,s very nice , s very nice