Results 1 to 9 of 9
Thread: how to read or get hidden input
- 12-11-2012, 05:39 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
how to read or get hidden input
Hi,
im using the foll code to read input for password.
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter your passw\n");
read.readLine();
although this works, the password is visible upfront. so when the user types he should see the chars typed in hidden or asterick or dotted format such that the passw is not visible.
can someone help on the same
rgds
Shravee
- 12-11-2012, 06:00 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: how to read or get hidden input
Nope.
Not without using something like an ncurses api.Please do not ask for code as refusal often offends.
- 12-11-2012, 06:06 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: how to read or get hidden input
There's a Console class that can do it.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-11-2012, 06:14 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: how to read or get hidden input
Crikey.
I sit corrected!
:)Please do not ask for code as refusal often offends.
- 12-11-2012, 07:43 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: how to read or get hidden input
We're not angry, only sad ...
kind regards,
Jos ;-)When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-12-2012, 02:38 AM #6
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Re: how to read or get hidden input
can you help me with this.
i tried the foll code but im not able to get inside the if loop.
Console console = System.console();
if (console != null) {
// Read username from the console
String username = console.readLine("Username: ");
// Read password
char[] password = console.readPassword("Password: ");
}
- 12-12-2012, 08:33 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: how to read or get hidden input
Did you try to run this from a command line shell/interpreter? Als read the API documentation for the Console class again (it also mentions the availability of a Console).
kind regards,
Jos
ps. the 'if' statement is not a loop.When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-17-2012, 03:13 AM #8
Member
- Join Date
- Dec 2012
- Posts
- 4
- Rep Power
- 0
Re: how to read or get hidden input
hi Josh, thanks it worked from cmd prompt.
but why not from eclipse. what should i do to work from eclipse.
--shravee
- 12-17-2012, 07:06 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: how to read or get hidden input
Eclipse 'fakes' a console; look at the top line of Eclipse's console: it shows that it's running 'javaw', i.e. a console-less JVM. Eclipse uses the setIn( ... ), setOut( ... ) and setErr( ... ) methods from the System class to hook up its console to the system streams, but there is no OS console anywhere so the System class can't return one.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
read input file into array
By randoms:) in forum New To JavaReplies: 3Last Post: 04-23-2011, 08:52 AM -
Read input from keyboard
By bison in forum New To JavaReplies: 2Last Post: 11-20-2010, 06:48 PM -
[SELENIUM] Retrieve the value of a hidden input type
By gecko753 in forum Web FrameworksReplies: 1Last Post: 11-04-2009, 03:32 PM -
How to read input from console
By Java Tip in forum java.ioReplies: 0Last Post: 04-16-2008, 10:57 PM -
How to read input from the console
By Java Tip in forum java.ioReplies: 0Last Post: 04-06-2008, 07:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks