read a passwort from input

S

Sven Bluege

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
 
M

Matt Humphrey

Sven Bluege said:
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 (e-mail address removed) http://www.iviz.com/
 
T

Thomas G. Marshall

Matt Humphrey coughed up:
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 (e-mail address removed) 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.
 
C

Chris Head

-----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-----
 
T

Thomas Weidenfeller

Thomas said:
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
 
T

Thomas G. Marshall

Thomas Weidenfeller said:
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....
 
T

Thomas Weidenfeller

Thomas said:
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
 
T

Thomas G. Marshall

Thomas Weidenfeller said:
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]...
 
T

Thomas Weidenfeller

Thomas said:
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.
 
T

Thomas G. Marshall

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top