I want to ask users to type in a password, but i dont want the chars to appear on screen as they type.
How do I do this in Ruby?
Thanks
I want to ask users to type in a password, but i dont want the chars to appear on screen as they type.
How do I do this in Ruby?
Thanks
There is a gem for such user interaction: highline.
password = ask("Password: ") { |q| q.echo = false }
Or even:
password = ask("Password: ") { |q| q.echo = "*" }
If you're on a system with stty
:
`stty -echo`
print "Password: "
pw = gets.chomp
`stty echo`
puts ""