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.
Marc S. (Guest)
on 2007-05-09 06: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
Doug P. (Guest)
on 2007-05-09 08:49
(Received via mailing list)
> -----Original Message-----
> From: Marc S. [mailto:removed_email_address@domain.invalid]
> 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)
Jeremy H. (Guest)
on 2007-05-09 08:57
(Received via mailing list)
On Wed, May 09, 2007 at 11:46:35AM +0900, Marc S. 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
Brian C. (Guest)
on 2007-05-09 15:10
(Received via mailing list)
On Wed, May 09, 2007 at 11:46:35AM +0900, Marc S. 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
Xavier N. (Guest)
on 2007-05-09 15:23
(Received via mailing list)
On May 9, 2007, at 4:46 AM, Marc S. 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
Marc S. (Guest)
on 2007-05-09 16:50
(Received via mailing list)
On 5/9/07, Xavier N. <removed_email_address@domain.invalid> wrote:
> On May 9, 2007, at 4:46 AM, Marc S. 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
Bruce W. (Guest)
on 2007-05-10 03:42
(Received via mailing list)
From the command line?

stty -echo
Dan Z. (Guest)
on 2007-05-10 11: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.