code_junkie

How to read a password in Ruby

Nov 11th, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. require 'rubygems'
  2. require 'highline/import'
  3.  
  4. def get_password(prompt="Enter Password")
  5. ask(prompt) {|q| q.echo = false}
  6. end
  7.  
  8. thePassword = get_password()
  9.  
  10. system "stty -echo"
  11. # read password
  12. system "stty echo"
  13.  
  14. #!/usr/local/bin/ruby
  15. require 'rubygems'
  16. require 'highline/import'
  17.  
  18. username = ask("Enter your username: ") { |q| q.echo = true }
  19. password = ask("Enter your password: ") { |q| q.echo = "*" }
  20.  
  21. $ ruby highline.rb
  22. Enter your username: doug
  23. Enter your password: ******
Add Comment
Please, Sign In to add comment