The Artima Developer Community
Sponsored Link

Java Answers Forum
accept password in dos using java

3 replies on 1 page. Most recent reply: Jun 11, 2002 5:11 AM by vinodh

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Janu

Posts: 8
Nickname: janu
Registered: May, 2002

accept password in dos using java Posted: May 19, 2002 12:31 AM
Reply to this message Reply
Advertisement
Hi..
I want to accept the Password from the user in DOS using java.the password must be taken in astriks.was there any way?


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: accept password in dos using java Posted: May 19, 2002 12:58 AM
Reply to this message Reply
This kind of thing would normally be done with functions in conio.h (like getch()), whereas Java only has buffered I/O on the console, as far as I know. It would be pretty easy to write a little native method that does the trick, by calling getch() to get characters and putting (putch()) a '*' for each character (besides backspace, enter, etc.). The same source might compile for both UNIX and DOS, as well.

Janu

Posts: 8
Nickname: janu
Registered: May, 2002

Please get me the code Posted: May 19, 2002 1:16 AM
Reply to this message Reply
i am not good with native methods,cone you give the example...

vinodh

Posts: 2
Nickname: vinodh
Registered: Jun, 2002

Re: Please get me the code Posted: Jun 11, 2002 5:11 AM
Reply to this message Reply
Hope this method will help u to read password.....

public String readPassword () {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Clear clear= new Clear( System.out );
clear.start ();
String password = "";
try {
password = in.readLine();
} catch ( IOException ioe ) {
}
clear.interrupt ();
try {
Thread.sleep ( 100 );
} catch (InterruptedException inte ) {
}
return password;
}
/**thread to
* replace each character with asterisk
*/
class Clear extends Thread {
PrintStream out;
boolean finish=false;
public Clear (PrintStream out) {
this.out = out;
}
public void run () {
while ( !finish ) {
out.print ( "\010*" );
try {
sleep ( 10 );
} catch ( InterruptedException inte ) {
finish = true;
}
}
}
}

Flat View: This topic has 3 replies on 1 page
Topic: novice question about threads: AccessControlException? Previous Topic   Next Topic Topic: CLASSPATHs in Win98.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use