Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > reading password from stdin

Reply
Thread Tools

reading password from stdin

 
 
Logan Capaldo
Guest
Posts: n/a
 
      03-21-2005
On Tue, 22 Mar 2005 04:24:53 +0900, vladimir konrad <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
 
vladimir konrad
Guest
Posts: n/a
 
      03-21-2005
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
 
Reply With Quote
 
 
 
 
Chris Mueller
Guest
Posts: n/a
 
      03-21-2005
Logan Capaldo wrote:

>On Tue, 22 Mar 2005 04:24:53 +0900, vladimir konrad <(E-Mail Removed)> 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


 
Reply With Quote
 
Csaba Henk
Guest
Posts: n/a
 
      03-21-2005
On 2005-03-21, Chris Mueller <(E-Mail Removed)> 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.


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
 
Reply With Quote
 
vladimir konrad
Guest
Posts: n/a
 
      03-22-2005
> system "stty -echo"
> system "stty echo"


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

Vlad
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 05-17-2013 04:30 PM
How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute() Ben C Programming 2 08-29-2009 09:47 PM
STDIN, OUT, ERR and $stdin, out, err - Differences? Terry Cooper Ruby 7 06-09-2009 05:48 AM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments