Password Echo

M

Marc Soda

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
 
D

Doug Phillips

-----Original Message-----
From: Marc Soda [mailto:[email protected]]=20
Sent: Tuesday, May 08, 2007 9:47 PM
To: ruby-talk ML
Subject: Password Echo
=20
Anyone know of a way, aside from Ruby/Password, of=20
suppressing echo for a password prompt on a terminal? I'm=20
interested in *nix primarily.

curses comes to mind (Curses.noecho() would suppress the echoing of the
text)
 
J

Jeremy Hinegardner

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
 
B

Brian Candler

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
 
X

Xavier Noria

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
 
M

Marc Soda

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
 
D

Dan Zwell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top