cymon has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm writing a CGI program that connects to a MySQL database using DBI. I would like to remove the username and password from the source of the script itself and--ideally--store it somewhere that can't be seen by others, save perhaps the machine's administrators.
(For the record, I did use search and super-search pretty carefully. While there are a lot of nodes on the system, I didn't see precisely the answer I was looking for. I'll admit, however, that I was overwhelmed by the number of hits and may have missed something while trying to scan them quickly.)
To begin, consider the following code (which is nothing special):
#!/usr/bin/perl -w use strict; use DBI(); my $dbh = DBI->connect( "DBI:mysql:database=mydb;host=localhost", "mywebuser", "mypassword", { 'RaiseError' => 1 } ); my $sth = $dbh->prepare( "SELECT * from mytable;" ); $sth->execute(); while ( my $ref = $sth->fetchrow_hashref() ) { print "Found a row: id = $ref->{ 'id' }, name = $ref->{ 'name' }\n"; } $sth->finish(); $dbh->disconnect;
That said, here's my question: How do I protect the password, as well as (preferably) the user name used to access the database?
I have considered encrypting the password, perhaps with an MD5 hash, but I'm not sure how to handle the decryption process without compromising the password. I am not asking for ways to obscure the password, but to truly protect it from prying eyes. (If this is a good idea, I could also use some pointers that might help avoid common mistakes.)
Thanks in advance for any help...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Handling Passwords Securely
by Abigail-II (Bishop) on Feb 23, 2004 at 21:22 UTC | |
|
Re: Handling Passwords Securely
by cees (Curate) on Feb 23, 2004 at 21:32 UTC | |
|
Re: Handling Passwords Securely
by saintmike (Vicar) on Feb 23, 2004 at 21:23 UTC | |
|
Re: Handling Passwords Securely
by waswas-fng (Curate) on Feb 23, 2004 at 21:27 UTC | |
|
Re: Handling Passwords Securely
by mutated (Monk) on Feb 23, 2004 at 22:45 UTC | |
|
Re: Handling Passwords Securely
by freddo411 (Chaplain) on Feb 24, 2004 at 00:53 UTC |