Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

how to make a password dissapear?

by defyance (Curate)
on Dec 27, 2001 at 05:33 UTC ( #134529=perlquestion: print w/replies, xml ) Need Help??

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

I wrote a small prog using perl and Net::Telnet, that logs into a box and runs a small command of the users choice (i.e. ping, w, finger). To keep security risks down and so it can be used by miltiple persons, it reads <STDIN> for the users username and pass. But I can't seem to conceal the password. Any ideas? I'm pretty new to perl, But I think I understand the basics.

Replies are listed 'Best First'.
(Ovid - how to find odd answers) Re: how to make a password dissapear?
by Ovid (Cardinal) on Dec 27, 2001 at 06:09 UTC

    I recently answered this question on the beginners-perl mailing list. I think you might find the reponse very helpful.

    use Term::ReadKey; ReadMode('noecho'); $password = ReadLine(0);

    I've never used that before but some may be curious how I found it. Here's the trick:

        perldoc perltoc > perltoc.txt

    That sends the perltoc (Perl Table of Contents) to a text file. I sometimes scan through this file to pick up new tricks. When I see something that interests me (such as "password"), I scan through the relevant entries. In this case, I saw the following entries:

        How do I clear the screen?
        How do I get the screen size?
        How do I ask the user for a password?
        How do I read and write the serial port?

    The one about asking a user for a password looked useful, so I typed in:

        perldoc -q "How do I ask the user for a password?"

    That actually gave a lot more information than what I sent you, so you should give it a try :)

    The '-q' options stands for "FAQ keyword", but it can just as easily stand for 'question'.


    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

(ichimunki) Re: how to make a password dissapear?
by ichimunki (Priest) on Dec 27, 2001 at 05:56 UTC
(crazyinsomniac) Re: how to make a password dissapear?
by crazyinsomniac (Prior) on Dec 27, 2001 at 09:55 UTC
      Sweet guys thanks for all of the input. Problem is restrictions on the Machine I'm running on. They don't like us to have too much du and won't let me get any modules. I just have to use the one's they allocate. Maybe, hopefully, I can convince the admin(a good friend) to grab a small list of modules for this little project, and many future projects as I'm really liking the functionality I can get outta perl.

        No offense, but this is kind of retarded. Code takes up space. Whether it's in the form of a pre-written, tested and robust module or in the form of proprietary code that you write/re-invent specifically for this project, it's going to take up disk space. I'll leave it up to you and your admins to determine which solution takes less time to code and support.

        Granted, in this case you can get by with a small amount of code, I think it's rather silly to deny the installation of modules because of disk space restrictions. Perl code doesn't take up a lot of space anyway, and disk space is cheap.

Re: how to make a password dissapear?
by defyance (Curate) on Dec 28, 2001 at 22:39 UTC
    Yesterday, while romping around the Monastery, I found the answer I was looking for. I don't remember which thread provided the answer as I was so excited when I found it, I lost it somehow. So I'll post the snippett in hopes that the person will take credit, so I can thank them. Sometimes the answer your looking for is right under your nose...
    system('/usr/bin/stty', '-echo'); chomp($password=<STDIN>); system('/usr/bin/stty', 'echo');
      I have to admit, that looks like you're trying way too hard.

      I'd probably give Term::ReadKey a shot if I were you.

      use Term::ReadKey; ReadMode 2; chomp( my $password = ReadLine ); ReadMode 0;
         I am a superhero.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-01-30 21:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found