read a passwort from input

Discussion in 'Java' started by Sven Bluege, Jun 13, 2005.

  1. Sven Bluege

    Sven Bluege Guest

    Hello!

    Is it possible to read a password from commandline? System.in can only
    read a full line after a Return, but I want to read every keystroke and
    I want to decide, if the character will be shown in commandline or not.

    Thanks, Sven Bluege
     
    Sven Bluege, Jun 13, 2005
    #1
    1. Advertising

  2. "Sven Bluege" <> wrote in message
    news:xn0e3g79r87rtv8002@192.168.0.2...
    > Hello!
    >
    > Is it possible to read a password from commandline? System.in can only
    > read a full line after a Return, but I want to read every keystroke and
    > I want to decide, if the character will be shown in commandline or not.


    Whether or not the command line is echoed or buffers to a carriage return
    depends on the OS settings, not Java. DOS Bat files include "echo off" and
    Unix has many settings for controlling stream appearance. You'll have to
    look up a technique specific to your platform. This question has been asked
    often before, so you should be able to find an answer for your platform.

    Cheers,
    Matt Humphrey http://www.iviz.com/
     
    Matt Humphrey, Jun 13, 2005
    #2
    1. Advertising

  3. Matt Humphrey coughed up:
    > "Sven Bluege" <> wrote in message
    > news:xn0e3g79r87rtv8002@192.168.0.2...
    >> Hello!
    >>
    >> Is it possible to read a password from commandline? System.in can
    >> only read a full line after a Return, but I want to read every
    >> keystroke and I want to decide, if the character will be shown in
    >> commandline or not.

    >
    > Whether or not the command line is echoed or buffers to a carriage
    > return depends on the OS settings, not Java. DOS Bat files include
    > "echo off" and Unix has many settings for controlling stream
    > appearance. You'll have to look up a technique specific to your
    > platform. This question has been asked often before, so you should be
    > able to find an answer for your platform.
    >
    > Cheers,
    > Matt Humphrey http://www.iviz.com/



    Yep. I would understand the OP's frustration here, however. *Years* ago, a
    friend of mine tried to build an entire application hovering around a
    misconception that she could have fine-tuned control over DOS vs. unix shell
    (etc.) input in java.

    The brutal fact hit her that java could not control such things. She opted
    for a window-driven, but primarily text based (in the window) interface.
    Document models I think.

    I spent some time wonderring if there could be such a way to control the
    invoking text box in a cross platform way. Output as well as input. I
    speculated that perhaps a curses-like facility would be possible, but lost
    interest before continuing further in the thought process.


    --
    Whyowhydidn'tsunmakejavarequireanuppercaselettertostartclassnames....
     
    Thomas G. Marshall, Jun 30, 2005
    #3
  4. Sven Bluege

    Chris Head Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Thomas G. Marshall wrote:
    [snip]
    > I spent some time wonderring if there could be such a way to control the
    > invoking text box in a cross platform way. Output as well as input. I
    > speculated that perhaps a curses-like facility would be possible, but lost
    > interest before continuing further in the thought process.
    >
    >



    Never used it, but:
    http://sourceforge.net/projects/javacurses/

    (I know you're not looking for an answer here, I just thought I'd throw
    it out for discussion - however the OP may find it useful)

    Chris
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.1 (MingW32)

    iD8DBQFCxF1ggxSrXuMbw1YRAs7sAJ46pt6kcyuETw5D3ZzQxKE0WsOtXQCg0t1E
    WP4YhMCT/sBd0+KRHIOw76c=
    =gWyS
    -----END PGP SIGNATURE-----
     
    Chris Head, Jun 30, 2005
    #4
  5. Thomas G. Marshall wrote:
    > The brutal fact hit her that java could not control such things. She opted
    > for a window-driven, but primarily text based (in the window) interface.
    > Document models I think.
    >
    > I spent some time wonderring if there could be such a way to control the
    > invoking text box in a cross platform way. Output as well as input. I
    > speculated that perhaps a curses-like facility would be possible, but lost
    > interest before continuing further in the thought process.


    There are several curses implementations around for Java, like JCurses.

    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Jul 1, 2005
    #5
  6. "Thomas Weidenfeller" <> wrote in message
    news:da2r9h$tv2$...
    > Thomas G. Marshall wrote:
    >> The brutal fact hit her that java could not control such things. She
    >> opted for a window-driven, but primarily text based (in the window)
    >> interface. Document models I think.
    >>
    >> I spent some time wonderring if there could be such a way to control the
    >> invoking text box in a cross platform way. Output as well as input. I
    >> speculated that perhaps a curses-like facility would be possible, but
    >> lost interest before continuing further in the thought process.

    >
    > There are several curses implementations around for Java, like JCurses.


    I wonder what they're doing. You cannot get around the fact that the
    command line environment (whatever it is) is in charge of giving characters
    to a java app in whatever way it chooses. Are they doing something
    dastardly in JNI I wonder....



    >
    > /Thomas
    >
    > --
    > The comp.lang.java.gui FAQ:
    > ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    > http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas G. Marshall, Jul 12, 2005
    #6
  7. Thomas G. Marshall wrote:
    > I wonder what they're doing. You cannot get around the fact that the
    > command line environment (whatever it is) is in charge of giving characters
    > to a java app in whatever way it chooses. Are they doing something
    > dastardly in JNI I wonder....


    All the ones I have seen do the normal thing which C curses and other
    libraries do: The use the terminal interface (communicate with the
    terminal device driver) to do the I/O. No magic involved.

    man termio
    man termios

    The last Java curses which I had a look at was in fact simply using the
    normal C curses library via JNI, instead of implementing any termio /
    termios handling via JNI on its own.


    /Thomas
    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Jul 12, 2005
    #7
  8. "Thomas Weidenfeller" <> wrote in message
    news:db0o3r$nrd$...
    > Thomas G. Marshall wrote:
    >> I wonder what they're doing. You cannot get around the fact that the
    >> command line environment (whatever it is) is in charge of giving
    >> characters to a java app in whatever way it chooses. Are they doing
    >> something dastardly in JNI I wonder....

    >
    > All the ones I have seen do the normal thing which C curses and other
    > libraries do: The use the terminal interface (communicate with the
    > terminal device driver) to do the I/O. No magic involved.


    Assuming a unix-esque platform? There's quite a bit of "magic" involved if
    its on a mac pre-OSX, for example.

    ....[rip]...


    > The last Java curses which I had a look at was in fact simply using the
    > normal C curses library via JNI


    Which meant that you needed to have one on your system to start with. IMO,
    this is a far more complicated problem than you're making it sound.

    ....[rip]...
     
    Thomas G. Marshall, Jul 12, 2005
    #8
  9. Thomas G. Marshall wrote:
    > Assuming a unix-esque platform?


    Well yes, particularly because curses is an old Unix library (a spin-of
    of the beloved vi editor: vi's screen control code was factored out into
    a library and curses was born).

    > There's quite a bit of "magic" involved if
    > its on a mac pre-OSX, for example.


    I don't know pre-OS X Macs. Do they have a native library or API for
    text console output? If yes, could one wrap that in a JNI wrapper and
    use it? Just like the Unix people wrapped curses in a JNI wrapper.
    Alternatively, you could first wrap that (assumed) native Mac API into a
    curses emulation layer and then that emulation into a JCurses API.

    BTW, if there is no text I/O on pre-OS X Macs, why would one develop a
    text application for it? And isn't the JVM on this OS rather old? So
    maybe Java is not a good choice for this OS at all?

    > Which meant that you needed to have one on your system to start with. IMO,
    > this is a far more complicated problem than you're making it sound.


    I know that there are C curses/ncurses implementations for Windows. And
    Windows definitely doesn't have the Unix termio terminal interface
    structure at all. So if it could be done for Windows, I wouldn't regard
    it as impossible for other platforms.

    /Thomas

    PS: Maybe there is one thing which I didn't express clearly: I am not
    promoting Java text UI applications. Java is ill-suited for this, and
    any fix requires native libraries, which hinders cross-platform portability.

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Jul 12, 2005
    #9
  10. Thomas Weidenfeller coughed up:

    ....[rip]...


    > PS: Maybe there is one thing which I didn't express clearly: I am not
    > promoting Java text UI applications. Java is ill-suited for this, and
    > any fix requires native libraries, which hinders cross-platform
    > portability.


    Yes.

    However, it's not that you were promoting anything in particular, it's that
    you were speaking as if it were a simple issue, and it is not, and the
    solutions you /did/ give were unix specific.



    --
    I've seen this a few times--Don't make this mistake:

    Dwight: "This thing is wildly available."
    Smedly: "Did you mean wildly, or /widely/ ?"
    Dwight: "Both!", said while nodding emphatically.

    Dwight was exposed to have made a grammatical
    error and tries to cover it up by thinking
    fast. This is so painfully obvious that he
    only succeeds in looking worse.
     
    Thomas G. Marshall, Jul 12, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weng Tianxiang
    Replies:
    12
    Views:
    1,685
  2. Sven Bluege
    Replies:
    0
    Views:
    1,233
    Sven Bluege
    Jun 13, 2005
  3. ashutosh
    Replies:
    3
    Views:
    9,034
    Andrew Thompson
    Jun 16, 2005
  4. Guy
    Replies:
    5
    Views:
    2,858
    brucie
    Dec 13, 2003
  5. Melissa
    Replies:
    2
    Views:
    634
    Gaurav Vaish \(a.k.a. MasterGaurav\)
    Dec 26, 2008
Loading...

Share This Page