in reply to Hiding/masking your username or password

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.

Replies are listed 'Best First'.
Re^2: Hiding/masking your username or password
by JavaFan (Canon) on Nov 28, 2009 at 13:31 UTC
    In the case of mysql: mysql can read a password (and other command line options) from a configuration file. No need to pass mysql passwords on the command line.