Forum: Ruby Password Echo

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5892288702862ce1bf3fe2ae54745e72?d=identicon&s=25 Marc Soda (Guest)
on 2007-05-09 04:47
(Received via mailing list)
Anyone know of a way, aside from Ruby/Password, of suppressing echo
for a password prompt on a terminal?  I'm interested in *nix
primarily.

Thanks,
Marc
7b0e3a2c135e6f67edf3194ee501961d?d=identicon&s=25 Doug Phillips (Guest)
on 2007-05-09 06:49
(Received via mailing list)
> -----Original Message-----
> From: Marc Soda [mailto:marcantoniosr@gmail.com]
> Sent: Tuesday, May 08, 2007 9:47 PM
> To: ruby-talk ML
> Subject: Password Echo
>
> Anyone know of a way, aside from Ruby/Password, of
> suppressing echo for a password prompt on a terminal?  I'm
> interested in *nix primarily.

curses comes to mind (Curses.noecho() would suppress the echoing of the
text)
Ae36591847393e58ff189704f5eb18f2?d=identicon&s=25 Jeremy Hinegardner (Guest)
on 2007-05-09 06:57
(Received via mailing list)
On Wed, May 09, 2007 at 11:46:35AM +0900, Marc Soda wrote:
> Anyone know of a way, aside from Ruby/Password, of suppressing echo
> for a password prompt on a terminal?  I'm interested in *nix
> primarily.

HighLine can take care of this for you.

    > cat password.rb
    require "rubygems"
    require "highline/import"

    pass = ask("Enter your password:  ") { |q| q.echo = '*' }
    puts "Your password is `#{pass}'!"

    > ruby password.rb
    Enter your password:  ********************************************
    Your password is `This is how you do a password prompt in ruby'!

If you set q.echo = false then you will have nothing echoed on the
terminal.

If you want to roll your own on *nix boxes, you'll need to become
familiar with stty(1).

enjoy,

-jeremy
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-05-09 13:10
(Received via mailing list)
On Wed, May 09, 2007 at 11:46:35AM +0900, Marc Soda wrote:
> Anyone know of a way, aside from Ruby/Password, of suppressing echo
> for a password prompt on a terminal?  I'm interested in *nix
> primarily.

ruby-termios
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2007-05-09 13:23
(Received via mailing list)
On May 9, 2007, at 4:46 AM, Marc Soda wrote:

> Anyone know of a way, aside from Ruby/Password, of suppressing echo
> for a password prompt on a terminal?  I'm interested in *nix
> primarily.

It's trivial with HighLine.

-- fxn
5892288702862ce1bf3fe2ae54745e72?d=identicon&s=25 Marc Soda (Guest)
on 2007-05-09 14:50
(Received via mailing list)
On 5/9/07, Xavier Noria <fxn@hashref.com> wrote:
> On May 9, 2007, at 4:46 AM, Marc Soda wrote:
>
> > Anyone know of a way, aside from Ruby/Password, of suppressing echo
> > for a password prompt on a terminal?  I'm interested in *nix
> > primarily.
>
> It's trivial with HighLine.
>
> -- fxn
>

Thanks all.  I was hoping that there was a way I overlooked that
didn't require any external dependencies.  However, I ended up using
ruby-termios.

Marc
8cfdf47d27893fbd55d6b9565c34fbe4?d=identicon&s=25 Bruce Woodward (Guest)
on 2007-05-10 01:42
(Received via mailing list)
From the command line?

stty -echo
Caf38c89d40443a858741b61ac6d82de?d=identicon&s=25 Dan Zwell (Guest)
on 2007-05-10 09:03
(Received via mailing list)
> Thanks all.  I was hoping that there was a way I overlooked that
> didn't require any external dependencies.  However, I ended up using
> ruby-termios.
>
> Marc
>
>

Marc--I use:

     begin
       system "stty -echo"
       @password = gets.chomp
     ensure
       system "stty echo"
     end

It turns off terminal echoing, ensuring that the script can't end before
turning echoing back on.

Dan
This topic is locked and can not be replied to.