How can I enter a password using Perl and replace the characters with '*'?

Matthew Farwell picture Matthew Farwell · Mar 31, 2009 · Viewed 34.1k times · Source

I have a Perl script that requires the user to enter a password. How can I echo only '*' in place of the character that the user types, as they type it?

I'm using Windows XP/Vista.

Answer

Peter Stuifzand picture Peter Stuifzand · Apr 2, 2009

In the past I have used IO::Prompt for this.

use IO::Prompt;
my $password = prompt('Password:', -e => '*');
print "$password\n";