From: Pablo Lorenzzoni Date: 2002-08-29T06:35:45+09:00 Subject: Re: Stdin Password Reading Hello! Thanx. for your tip. You're right! I use Debian GNU/Linux. []s Pablo Em Qua 28 Ago 2002 07:36, YANAGAWA Kazuhisa escreveu: | 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. -- Pablo Lorenzzoni (Spectra) GnuPG Key ID 268A084D at search.keyserver.net Webpage: http://people.debian.org/~spectra/