Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!