Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Answer: How do I make password prompts not echo back the user?

by Shendal (Hermit)
on Sep 20, 2000 at 21:47 UTC ( #33362=categorized answer: print w/replies, xml ) Need Help??

Q&A > input and output > How do I make password prompts not echo back the user? - Answer contributed by Shendal

Use Term::Readkey. It is more portable than the unix-only solution of stty. Here's a quick example (untested):
use Term::ReadKey; print "Type your password:"; ReadMode('noecho'); # don't echo chomp(my $password = <STDIN>); ReadMode(0); # back to normal

Cheers,
Shendal

Replies are listed 'Best First'.
Re: Answer: How do I make password prompts not echo back the user?
by isotope (Chaplain) on Mar 02, 2001 at 22:08 UTC
    You might want to try something more like:
    use Term::ReadKey; ReadMode('noecho'); # don't echo print "Type your password:"; chomp(my $password = <STDIN>); ReadMode(0); # back to normal
    ...so you only print the password prompt when echo has already been disabled. This makes your program more compatible with things like Expect, which may not wait long enough after the prompt for the echo to be disabled before sending the password.

    --isotope
    http://www.skylab.org/~isotope/
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[karlgoethebier]: nice
[LanX]: Mary_Allen_Wilkes

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-12-12 15:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (335 votes). Check out past polls.

    Notices?