Sometimes, you might want to obscure usernames or passwords in your scripts or configuration files. (this is a bad thing, but sometimes you don't have much choice).

This snippet can help by producing an unreadale (but trivially reversible) rendering of the sensitive data, thanks to the pack() and unpack() functions...

Update: Just to make it clearer for the AM, you can never keep scripts or config files hidden from the sysadmins, no matter what. In order to get to a password, your Perl has to be able to read it. If your Perl can, so can the sysadmin on your box. What this is supposed to do, is make it easier for the sysadmin not to read your sensitive data. I agree with the false sense of security though.

Update 2: As suggested by bart, the "u" has been a bit obscured. Thanks!

Update to the Update 1: I just saw a typo. I wrote AC instead of AM. My mistake and sorry for that.

# You would use something like this to create the obscured data... perl -e 'print pack("u", "justanotherperlhacker"), "\n"' # How to access your obscured data in your script... our $LOGIN = unpack(chr(ord("a") + 19 + print ""), "5:G5S=&%N;W1H97)P9 +7)L:&%C:V5R");

In reply to Obscuring sensitive data in your scripts by fokat

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.