Console input on Ruby: Masking passwords on the command line

I like plain old console applications. They are fast (to program, compile and use) and, of course, add a cool factor, like people saying they have absolutely no idea of what you are doing!

Ruby, of course, can do console apps, but it’s not trivial to read user input. And what if you want the user to type a password? You would like, of course, to show them asteriks ‘*’ or nothing at all instead of the plain text being typed.

Well, “highline” gem covers this and much more. What about writing:

ask("Enter your password:  " ) { |q| q.echo = "x" }

And that’s all! That’s quite cool, man. It can even check if the answer matches some regex, or split it by commas, or anything you want
Take a look at it: http://highline.rubyforge.org/

~ by Dante Regis on November 19, 2007.

2 Responses to “Console input on Ruby: Masking passwords on the command line”

  1. Thank you for pointing out this gem!!!

    PS. WordPress has messed up for you the code with image smilies…

  2. that’s right, ~Elia! Thanks. I’m fixing it right now.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: