You can obscure the information in the Perl code in various ways, but anyone who can read the code can execute the same operations to translate it back. For example, if the password consists of only lowercase alphabetic characters (as, sadly, too many do) a simple rot13:
$ perl -lwe ' use strict; my $password = "abcdefg"; $password =~ y/a-z/n-za-n/; print $password; ' nopqrst
(You can extend that to include uppercase, digits 0-9 with rot5 y/0-9/5-90-4/, and other characters similarly y/!@#$%^&*(){}[];:<>,./{}[];:<>,.!@#$%^&*()/)

Other possibilities include using pack/unpack, Data::Serializer, etc. You can store the obscured data in a separate file and read it in before de-obscuring it.

To keep the password off the command-line and thus out of ps -ef and equivalents, many commands have an option to prompt for the password. For those, something like echo $password | command -p may work. Other commands - mysql is one - will not accept the password that way. For some of those, Expect can be used.

None of these will keep a determined person from getting the information; they merely make him work a little bit more. They are, however, slightly better than plaintext passwords in the code.


In reply to Re: Hiding/masking your username or password by keszler
in thread Hiding/masking your username or password by newbie01.perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.