[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: reading password from stdin

Logan Capaldo

3/21/2005 7:43:00 PM

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

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.


3 Answers

Chris Mueller

3/21/2005 10:01:00 PM

0

Logan Capaldo wrote:

>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
>>
>>
>>
>>
>
>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...
http://raa.ruby-lang.org/project/rub...

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


Csaba Henk

3/21/2005 11:00:00 PM

0

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...
> http://raa.ruby-lang.org/project/rub...
>
> 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.

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

vladimir konrad

3/22/2005 8:11:00 PM

0

> system "stty -echo"
> system "stty echo"

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

Vlad