Reading password from stdin

Hello,

How to disable output when reading with readline on linux? The script needs
to read a password and I would like it not to display...

Any ideas?

Vladimir

I would imagine it would require 'curses'. A "simpler" method might be
figuring out what $TERM is and getting the proper escape sequences to
make the foreground the same color as the background. Off course,
that's kind of the point of curses...and if your script ends up on
some really weird terminal somewhere it might mess it up.

···

On Tue, 22 Mar 2005 04:24:53 +0900, vladimir konrad <bouncer@nowhere.org> wrote:

Hello,

How to disable output when reading with readline on linux? The script needs
to read a password and I would like it not to display...

Any ideas?

Vladimir

Logan Capaldo wrote:

Hello,

How to disable output when reading with readline on linux? The script needs
to read a password and I would like it not to display...

Any ideas?

Vladimir

I would imagine it would require 'curses'. A "simpler" method might be
figuring out what $TERM is and getting the proper escape sequences to
make the foreground the same color as the background. Off course,
that's kind of the point of curses...and if your script ends up on
some really weird terminal somewhere it might mess it up.

You need the modules ruby-termios and ruby-password. Both of these are available from RAA

http://raa.ruby-lang.org/project/ruby-password/
http://raa.ruby-lang.org/project/ruby-termios/

You may run into problems with buffered/unbuffered inputs if any exceptions happen (ie prntscrn, ctrl+c etc.) but termios is used to mask the user input.

-Chris

···

On Tue, 22 Mar 2005 04:24:53 +0900, vladimir konrad <bouncer@nowhere.org> wrote:

To add, if you don't want to have these external dependencies, there is
a poor man's solution, namely:

system "stty -echo"
system "stty echo"

Csaba

···

On 2005-03-21, Chris Mueller <cmueller@bycast.com> wrote:

You need the modules ruby-termios and ruby-password. Both of these are
available from RAA

http://raa.ruby-lang.org/project/ruby-password/
http://raa.ruby-lang.org/project/ruby-termios/

You may run into problems with buffered/unbuffered inputs if any
exceptions happen (ie prntscrn, ctrl+c etc.) but termios is used to mask
the user input.

system "stty -echo"
system "stty echo"

Thank you all for replies, I went for the "stty" solution at the end.

Vlad