Home > programming, ruby > Console input on Ruby: Masking passwords on the command line

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/

Categories: programming, ruby Tags:
  1. ~Elia
    July 21st, 2008 at 07:57 | #1

    Thank you for pointing out this gem!!!

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

  2. July 21st, 2008 at 13:04 | #2

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

  1. No trackbacks yet.