Vincent Foley wrote:
> Hello James,
> 
> good job on the new release, I plan to use HighLine in an application I
> am building right now, however I would really like it if you could add
> an ask_password method.  Right now, I use this small hackish method:
> 
>     # File lib/helpers.rb, line 12
> 12:   def self.ask_password(prompt)
> 13:     print prompt
> 14:     system("stty -echo echonl")
> 15:     pass = gets.chomp
> 16:     system("stty echo -echonl")
> 17:     return pass
> 18:   end
> 
> Maybe something to add to your TODO :)

Especially if you can do it multi-platform (the above does not work on 
Windows.)

Here is a Windows version that I just wrote:

require 'Win32API'

@getch = Win32API.new("crtdll", "_getch", [], 'L')

def ask_password(prompt)
   print prompt
   pass = ''
   while ((c = @getch.call) != 13)
     pass << c.chr
   end
   pass
end

pass = ask_password("Please give me your password: ")
puts
puts "Got '#{pass}'"
__END__

There may be a better way, but this works. James, feel free to put this 
in HighLine, just give me the credit :)

Obviously this will need to be partitioned for the different platforms.

Another cool thing is you could take a block that checks the password 
for strength :)

Ryan