Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to read password from keyboard

0 views
Skip to first unread message

Bruno Sousa

unread,
Jul 29, 2010, 4:31:21 PM7/29/10
to
Hi everyone!

If I want to read a simple string from keyboard:
simple_text = gets

What if a password needs to be read from keyboard (commando line)?
How do I mask it with asterisks?

Regards,
Bruno
--
Posted via http://www.ruby-forum.com/.

James Harrison

unread,
Jul 29, 2010, 4:49:11 PM7/29/10
to
>
> If I want to read a simple string from keyboard:
> simple_text = gets
>
> What if a password needs to be read from keyboard (commando line)?
> How do I mask it with asterisks?


Try thinking of it like this:

every time a key is pressed on the keyboard, you want to:

print "*"

I don't have time right now to mock up an example, but that might get you started.

Guglielmo Fachini

unread,
Jul 29, 2010, 5:25:00 PM7/29/10
to
Bruno Sousa wrote:
> Hi everyone!
>
> If I want to read a simple string from keyboard:
> simple_text = gets
>
> What if a password needs to be read from keyboard (commando line)?
> How do I mask it with asterisks?
>
> Regards,
> Bruno

This can help you:
http://stackoverflow.com/questions/133719/how-to-read-a-password-in-ruby

Joseph E. Savard

unread,
Jul 29, 2010, 5:30:59 PM7/29/10
to
require 'rubygems'
require 'highline/import'

pwd = ask("Enter your password: " ) {|c| c.echo=false; c.echo='*';}

puts "the password=#{pwd}"

Joseph E. Savard

unread,
Jul 29, 2010, 5:34:37 PM7/29/10
to


c.echo=false; not needed... Only needs the c.echo='*'

Bruno Sousa

unread,
Jul 30, 2010, 8:02:35 AM7/30/10
to
Thanks everyone!
that's exactly what I wanted!
0 new messages