in reply to hiding password typing in Windows
You can use Term::ReadKey for that.
Update: In its most simple case, this could be something like
use Term::ReadKey; ReadMode 'noecho'; my $passw = ReadLine; ReadMode 'restore'; print "$passw\n"; # just to check
Or, if you want to use the console/tty instead of STDIN — which would keep people from piping in passwords (like echo foo | perl 758036.pl):
use Term::ReadKey; use Fcntl "O_RDWR"; if ($^O =~ /Win32/i) { sysopen IN, 'CONIN$', O_RDWR or die "Unable to open console for in +put: $!"; } else { open IN, "<", "/dev/tty" or die "Unable to open tty for input: $!" +; } ReadMode 'noecho', *IN; my $passw = ReadLine 0, *IN; ReadMode 'restore', *IN; print "$passw\n"; # just to check
Or, yet another version with rudimentary editing capabilities (backspace):
use Term::ReadKey; use Fcntl "O_RDWR"; if ($^O =~ /Win32/i) { sysopen IN, 'CONIN$', O_RDWR or die "Unable to open console for in +put: $!"; } else { open IN, "<", "/dev/tty" or die "Unable to open tty for input: $!" +; } ReadMode 'noecho', *IN; my ($ch, $passw); do { $ch = ReadKey 0, *IN; $passw .= $ch; substr($passw,-2)='' if ord($ch)==127; # BS } until ($ch eq "\n"); ReadMode 'restore', *IN; print "$passw\n";
|
|---|