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...
In reply to Handling Passwords Securely by cymon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |