Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

hiding input

by Octavian (Monk)
on Nov 17, 2000 at 02:03 UTC ( [id://42094]=perlquestion: print w/replies, xml ) Need Help??

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

Ok, here at my job, I have been tasked to re-write the passwd program to be more restrictive for HP. So I am doing it in perl. (its the government, I just do what I am told). Anyways, I always have used STDIN in the past, but that wont work good for this since that is echoed to the screen, and I need what a person types to be hidden to prevent people looking over shoulders n stuff. so it needs to be able to take imput while hiding it just like using passwd does. Any suggestions?

Replies are listed 'Best First'.
Re: hiding input
by arturo (Vicar) on Nov 17, 2000 at 02:09 UTC
    Term::Readkey is probably what you want to use, a la
    use Term::Readkey; ReadMode('noecho'); $pwd = ReadLine(0);

    (Lifted from the Perl Cookbook, p. 529)

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      tried this, and got the error:
      Can't locate Term/Readkey.pm in @INC (@INC contains: /opt/perl5/lib/PA-RISC1.1/5.00404 /opt/perl5/lib /opt/perl5/lib/site_perl/PA-RISC1.1 /opt/perl5/lib/site_perl .) at ./prog line 14. BEGIN failed--compilation aborted at ./prog line 14.
        You don't have the module installed, and you'll have to install the module, I'm afraid. If you have root access (or you can get the admin to do this for you) I'd advise using the CPAN module.
        perl -MCPAN -e 'install Term::Readkey'
        from the command line. Read perlmodinstall for more info on installing modules.

        Philosophy can be made out of anything. Or less -- Jerry A. Fodor

        You may yet have it installed. It's actually supposed to be use Term::ReadKey. Note the capital K in ReadKey.
(redmist) Re: hiding input
by redmist (Deacon) on Nov 17, 2000 at 02:11 UTC
    use Term::ReadKey; print "Enter your passwd: "; ReadMode 'noecho'; $passwd = ReadLine 0; chomp $passwd; ReadMode 'normal';

    From the Perl Cookbook, pg, 530.

    {EDIT: Dammit! arturo beat me by 2 minutes!}

    IDENTIFICATION DIVISION.
    PROGRAM-ID.  redmist.
    AUTHOR.  God (Larry Wall/Alan Cox hybrid).
    CONTACT.  redmist@users.sourceforge.net
    
Re: hiding input
by cianoz (Friar) on Nov 17, 2000 at 04:28 UTC
    as many have told you, you should install and use Term::Readkey, however there is another (dirty) way (at least on unix):
    system('stty -echo'); print "insert key:"; $key = <STDIN>; system('stty echo');
      tried this, and it works great...I am gonna have to use this method. I played around with installing the module on our test box, just to learn a little on how it all works n stuff, but the powers that be wont let me install "extra stuff" on all of our servers. so this is a great alternative...thank you ;)
Re: hiding input
by Anonymous Monk on Nov 18, 2000 at 11:09 UTC
    If you are working on UNIX platform, this is an easier task. Use optionally echoing of input facility of UNIX. Try this :
    printf("Enter word :"); chomp($visible_word = <STDIN>>); #### you can see what you are typin +g ... printf("\n"); system("stty -echo"); chomp($passwd = <STDIN>); #### this won't be visible on screen ... printf("\n"); system("stty echo");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://42094]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found