I may be misunderstanding your point about storing the password in a file "makes it more difficult to control security".
We have several hundred pages of CGI that have to access our mySQL database and in our own attempt to make the system more secure (this system is not on a public web, but only available to our employees..but still, it doesn't hurt to be careful) as well as easier to code and manage, we store the mySQL username/password info in a seperate file .
Here is the code for the file that sets up the mySQL connection
package Data_config;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
$DBHOST
$DBPORT
$DBDRIVER
$DATABASE
$USERNAME
$PASSWORD
);
## Database configuration ##
our $DBHOST = "localhost";
our $DBPORT = "3306";
our $DBDRIVER = "mysql";
our $DATABASE = "database";
our $USERNAME = "database";
our $PASSWORD = "password";
We can then make our mySQL setups in each of our CGI scripts with
## Create a database handle ##
my $DSN = "DBI:$DBDRIVER:database=$DATABASE:host=$DBHOST:port=$DBPORT"
+;
my $DBH = DBI->connect($DSN, $USERNAME, $PASSWORD, {
RaiseError => 1,
PrintError => 1
});
this gives us not only the security of not having the mySQL username/passwords in the CGI but also makes it very easy to change the username/passwords on the server since they are stored in one location.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.