s_gaurav1091 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a perl script wherein I want to get the username/password for logging to a particular application.
print "\nlogin: "; $username = <STDIN>; chomp($username); print "Password: "; $password = <STDIN>; chomp($password);
Bu this will show the password on the console. I don't want the password to be displayed when the user types in. I know we have a perl module Term::ReadLine through which we can do this. But I don't want to use this perl module. Please suggest. Thanks in advance

Replies are listed 'Best First'.
Re: Getting user input from STDIN
by waldner (Beadle) on Jun 21, 2008 at 11:16 UTC
    See perl FAQ 8, "How do I ask the user for a password"?
Re: Getting user input from STDIN
by FunkyMonk (Bishop) on Jun 21, 2008 at 11:17 UTC
Re: Getting user input from STDIN
by CountZero (Bishop) on Jun 21, 2008 at 21:05 UTC
    Can you explain why you would not like to use Term::ReadLine? It is a core module since Perl 5.04.

    To me it looks the same as saying, "I want to drop the end-of-line character but I do not want to use chop or chomp or substr> and regexes are evil too."

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Getting user input from STDIN
by alexm (Chaplain) on Jun 21, 2008 at 19:38 UTC

    crypt has an example which uses stty command:

    $pwd = (getpwuid($<))[1]; system "stty -echo"; print "Password: "; chomp($word = <STDIN>); print "\n"; system "stty echo"; if (crypt($word, $pwd) ne $pwd) { die "Sorry...\n"; } else { print "ok\n"; }

    However, this trick will only work on Unix-like systems.

Re: Getting user input from STDIN
by casiano (Pilgrim) on Jun 22, 2008 at 09:58 UTC