Results 1 to 9 of 9
  1. #1
    Shravee is offline Member
    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0

    Post 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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,003
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to read or get hidden input

    There's a Console class that can do it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: how to read or get hidden input

    Crikey.
    I sit corrected!
    :)
    Please do not ask for code as refusal often offends.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,003
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to read or get hidden input

    We're not angry, only sad ...

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Shravee is offline Member
    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0

    Default Re: how to read or get hidden input

    Quote Originally Posted by JosAH View Post
    There's a Console class that can do it.

    kind regards,

    Jos
    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: ");

    }

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,003
    Blog Entries
    7
    Rep Power
    20

    Default 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.
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Shravee is offline Member
    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0

    Default 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

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,003
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to read or get hidden input

    Quote Originally Posted by Shravee View Post
    hi Josh, thanks it worked from cmd prompt.

    but why not from eclipse. what should i do to work from eclipse.
    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. read input file into array
    By randoms:) in forum New To Java
    Replies: 3
    Last Post: 04-23-2011, 08:52 AM
  2. Read input from keyboard
    By bison in forum New To Java
    Replies: 2
    Last Post: 11-20-2010, 06:48 PM
  3. [SELENIUM] Retrieve the value of a hidden input type
    By gecko753 in forum Web Frameworks
    Replies: 1
    Last Post: 11-04-2009, 03:32 PM
  4. How to read input from console
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-16-2008, 10:57 PM
  5. How to read input from the console
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-06-2008, 07:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •