reading password from stdin

Discussion in 'Ruby' started by Logan Capaldo, Mar 21, 2005.

  1. On Tue, 22 Mar 2005 04:24:53 +0900, vladimir konrad <> 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.
     
    Logan Capaldo, Mar 21, 2005
    #1
    1. Advertising

  2. 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
     
    vladimir konrad, Mar 21, 2005
    #2
    1. Advertising

  3. Logan Capaldo wrote:

    >On Tue, 22 Mar 2005 04:24:53 +0900, vladimir konrad <> 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
     
    Chris Mueller, Mar 21, 2005
    #3
  4. Logan Capaldo

    Csaba Henk Guest

    On 2005-03-21, Chris Mueller <> 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
     
    Csaba Henk, Mar 21, 2005
    #4
  5. > system "stty -echo"
    > system "stty echo"


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

    Vlad
     
    vladimir konrad, Mar 22, 2005
    #5
    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. Johnathan Doe

    peek at stdin, flush stdin

    Johnathan Doe, May 15, 2004, in forum: C Programming
    Replies:
    5
    Views:
    25,042
    Chatoyer
    May 17, 2013
  2. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    793
    Dan Pop
    Jun 21, 2004
  3. AAaron123
    Replies:
    2
    Views:
    2,201
    AAaron123
    Jan 16, 2009
  4. AAaron123
    Replies:
    1
    Views:
    1,357
    Oriane
    Jan 16, 2009
  5. Stefano Sabatini
    Replies:
    6
    Views:
    295
    Stefano Sabatini
    Jul 29, 2007
Loading...

Share This Page