EHLO

* On 2003-03-11 13:57
* Szymon Drejewicz <drejewic / wsisiz.edu.pl> wrote:
> How to get string from console without echo? I need it for password
> reading.

Use termios available at

http://raa.ruby-lang.org/list.rhtml?name=ruby-termios

Sample usage (note that the input routine has the potential of
showing a strange behavior: When a star is shown for every password
character, the stars do not fit into one line and you use backspace
the stars in the first line will not vanish even if the corresponding
characters are deleted):

require 'termios'    # Use termios for non-echoing input of password

BS  =   8
LF  =  10
DEL = 127

#==============================================================================
# Prompt for and reads in a password. When `stars' is true display a star for
# each character when the password is entered, otherwise do not provide any
# visual feedback. BS (Backspace) and DEL (Delete or rubout) can be used to
# edit input.
#==============================================================================
def read_pass(stars)
  pass = ''

  $stdin.extend Termios
  oldt = $stdin.tcgetattr
  newt = oldt.dup
  newt.lflag &= ~(Termios::ECHO | Termios::ICANON)
  $stdin.tcsetattr(Termios::TCSANOW, newt)

  loop {
    c = $stdin.getc
    break if c == LF
    if (c == BS or c == DEL) and (not pass.empty?)
      pass.chop!
      print "#{BS.chr} #{BS.chr}" if stars
    else
      pass <<= c.chr
      print '*' if stars
    end
  }

  $stdin.tcsetattr(Termios::TCSANOW, oldt)
  print "\n"

  return pass
end

HTH

Josef 'Jupp' Schugt
-- 
.---------------------.              .------..---..-----..---..-----.
| http://jupp.tux.nu/ |              | jupp || @ || gmx || . || net |
`---------------------'              `------'`---'`-----'`---'`-----'