User Tools

Site Tools


perl:read_password_without_echo
sub readPassword {
	my ($prompt) = @_;
	$prompt ||= 'password: ';
	my $password;
	if (eval "require Term::ReadKey") { # runtime load
		Term::ReadKey->import(qw/ReadMode ReadLine/);
		local $|=1;
		ReadMode('noecho');
		print STDERR $prompt;
		chomp($password = ReadLine(0));
		ReadMode('normal');
		print STDERR "\n";
	} else {
		print STDERR "WARNING: Unable to load Term::ReadKey -- TYPED PASSWORDS WILL BE ECHOED!\n";
		print STDERR $prompt;
		chomp ($password = <STDIN>);
	}
	return $password;
}
perl/read_password_without_echo.txt · Last modified: 2009/08/13 09:56 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki