Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

( #33353=categorized question: print w/ replies, xml ) Need Help??
Contributed by reyjrar on Sep 20, 2000 at 21:23 UTC
Q&A  > input and output


Description:

so, I'm doing the whole talker thing and one thing I've always found annoying about some talkers is that when you are prompted for your passwd, it echoes the letters back to the screen. I know its possible in c to just turn the echo off temporarily, that way you can type your passwd and not have everyone looking over your shoulder see it.
anyone know how to do that in perl?

thanks,
-brad..

Answer: How do I make password prompts not echo back the user?
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
Answer: How do I make password prompts not echo back the user?
contributed by I0

use Term::ReadPassword;

Answer: How do I make password prompts not echo back the user?
contributed by Anonymous Monk

Here's how I did it using Term::Readkey

ReadMode ('noecho');
print "Enter Password: ";
chomp($pw = <STDIN>);
ReadMode ('restore');

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

The easiest solution, under Unix at least, is to call 'stty' to change the terminal's "echo" attribute. I know of no way to do this under Windows or any non-Unix platform, and there may be a more standardized way of doing this (such as via curses or some Term-based module):

print "login: " my $login = <>; print "Password: " system('/usr/bin/stty', '-echo'); # Disable echoing my $password = <>; system('/usr/bin/stty', 'echo'); # Turn it back on
Answer: How do I make password prompts not echo back the user?
contributed by strredwolf

In addition to Term::Readkey, you may want to write up your own linegetter with getc(STDIN). That way, you'll be able to trap all of the deletes/backspaces w/o having any problems.

Isn't there a Readline module?

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (9)
    As of 2014-08-23 10:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (173 votes), past polls