From: kjana@...4lab.to (YANAGAWA Kazuhisa) Date: 2002-08-28T19:36:22+09:00 Subject: Re: Stdin Password Reading In message <200208272131.SAA41799@server.valenciene> spectra@debian.org writes: > How can I read a password from stdin without showing it (showing stars > instead, for instance)? I mean as a login program should do, or as passwd > does. If I can assume you use a Unix like system and it supports termios interface, then using termios module like this: # get current termios value of $stdin. orig = Termios.getattr($stdin) tios = orig.dup # make new value to be set by resetting ECHO and ICANON bit of # local modes: see termios(4). tios.c_lflag &= ~(Termios::ECHO|Termios::ICANON) # set new value of termios for $stdin. Termios.setattr($stdin, Termios::TCSANOW, tios) begin while c = $stdin.getc # don't echoing and line buffering p c end ensure # restore original termios state. Termios::setattr($stdin, Termios::TCSANOW, orig) end # You can use curses extension for this purpose but using it for tiny # problem like this is not preferable. Or, use extension library interfacing to getpass(3).... I don't remember already that is, but believe writing such extension is not so difficult. -- kjana@dm4lab.to August 28, 2002 What can't be seen is what can't be there.