in reply to Reading a password with Term::ReadLine

use Term::ReadKey; ReadMode('noecho'); ReadMode('raw'); my $pass = ''; while (1) { my $c; 1 until defined($c = ReadKey(-1)); last if $c eq "\n"; print "*"; $pass .= $c; } ReadMode('restore'); print "\n[$pass]\n";

Thanks to asarih and BUU.

Replies are listed 'Best First'.
Re: Re: Reading a password with Term::ReadLine
by spartan (Pilgrim) on May 12, 2004 at 17:48 UTC
    ++ Great snippet, I actually have a use for this.
    May I suggest inserting the following, just before your 'use Term::ReadKey;' line?
    $|=1; #Turn on AutoFlush

    On my system (Sun solaris 9 perl 5.8.0) I was consistently seeing 1 less asterisk until I hit the enter key. This should provide a little less confusion for folks entering passwords and not seeing asterisks echoed immediately.
    Thanks.


    Very funny Scotty... Now PLEASE beam down my PANTS!