How to read password from keyboard

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

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.

Bruno S. 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:

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

require ‘rubygems’
require ‘highline/import’

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

puts “the password=#{pwd}”

Thanks everyone!
that’s exactly what I wanted!

Bruno