• Post Reply Bookmark Topic Watch Topic
  • New Topic

Console typing of password  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need to accept a password from console using streams.but the password characters should be displayed as * or space.How is it possible?

Regards
Rajasree
 
Ranch Hand
Posts: 657
Clojure Spring VI Editor
 
Rajasree R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you very much.
But I have a small problem.If I am running the example programs from the command prompt its working fine.But when I am running from eclipse its printingn the prompt continuously.
One another similar program which I got is here.
If I run this from eclise and enter any key in console the eclipse window will get closed.Why is it so?
The code is here:

import java.io.*;
import java.awt.*;

public class PwdConsole {
public static void main(String[] args) throws Exception {
ConsoleEraser consoleEraser = new ConsoleEraser();
System.out.print("Password? ");
BufferedReader stdin = new BufferedReader(new InputStreamReader(
System.in));
consoleEraser.start();
String pass = stdin.readLine();
consoleEraser.halt();
System.out.print("\b");
System.out.println("Password: '" + pass + "'");
}
}

class ConsoleEraser extends Thread {
private boolean running = true;

public void run() {
while (running) {
System.out.print("\b ");

}
}

public synchronized void halt() {
running = false;
}
}




Regards
Rajasree
 
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try (I didn't yet) to run another Java application for entering password. Since you have controls over in and out of such application, you can easily to block displaying any inputs. If you implement my approach, please share code and origin of the idea.
 
Rajasree R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In the link suggested by Mr.Steve Morrow
http://java.sun.com/features/2002/09/pword_mask.html the examples are like that.
But in that case also when I run it from eclipse its printing the prompt continuously,though it wont close the eclispe window as in the previous program(PwdConsole)

In commoand prompt all these are working fine.Any solution?
Regards
Rajasree
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!