Unix Technical Forum

Hiding MySQL username and password

This is a discussion on Hiding MySQL username and password within the MySQL forums, part of the Database Server Software category; --> Ok, I am a newbie. But now I have tried everything. My quest is to put the MySQL host ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 10:29 AM
Nosferatum
 
Posts: n/a
Default Hiding MySQL username and password

Ok, I am a newbie. But now I have tried everything. My quest is to put
the MySQL host name, user name, password, databasename and table-name
in a separate file outside our web domain and call these variables via
include (into my PHP-file).
But it wont work! The path & diectories are all fine, the PHP script
works perfect (at last before I decided to move this critical
information).

This is the script:
<?php //starts here...
include ("/home/secret/protect/the_imported_mysqldata.inc");
$link=LinkUp($host,$username,$password)or die("Cant connect");
mysql_select_db($db_name)or die("cant choose db");

$sql="SELECT secret_variable FROM $tbl_name WHERE username='$username'
AND password='$password'";
$result=mysql_query($sql);

(and so on)

here is the included "the_imported_mysqldata.inc":
<?php
$host="the.secret.host";
$username="secret_as_stone";
$password="very_secret";
$db_name="secret_db";
$tbl_name="the_actual_table";

function LinkUp($host,$username,$password)
{
$mysql_link=mysql_connect($host,$username,$passwor d);
return $mysql_link;
}
?>

What have I done wrong? Please??

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 10:30 AM
Willem Bogaerts
 
Posts: n/a
Default Re: Hiding MySQL username and password


> here is the included "the_imported_mysqldata.inc":
> <?php
> $host="the.secret.host";
> $username="secret_as_stone";


What happens if you use the require statement instead of include? If it
still does not want to connect, but does include the file, try using the
$GLOBALS array (like: $GLOBALS['host'] = 'the.secret.host'.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 10:30 AM
Sean
 
Posts: n/a
Default Re: Hiding MySQL username and password


"Nosferatum" <John.Olav.O@gmail.com> wrote in message
news:1175027060.627223.175550@n59g2000hsh.googlegr oups.com...
> Ok, I am a newbie. But now I have tried everything. My quest is to put
> the MySQL host name, user name, password, databasename and table-name
> in a separate file outside our web domain and call these variables via
> include (into my PHP-file).
> But it wont work! The path & diectories are all fine, the PHP script
> works perfect (at last before I decided to move this critical
> information).
>
> This is the script:
> <?php //starts here...
> include ("/home/secret/protect/the_imported_mysqldata.inc");
> $link=LinkUp($host,$username,$password)or die("Cant connect");
> mysql_select_db($db_name)or die("cant choose db");
>
> $sql="SELECT secret_variable FROM $tbl_name WHERE username='$username'
> AND password='$password'";
> $result=mysql_query($sql);
>
> (and so on)
>
> here is the included "the_imported_mysqldata.inc":
> <?php
> $host="the.secret.host";
> $username="secret_as_stone";
> $password="very_secret";
> $db_name="secret_db";
> $tbl_name="the_actual_table";
>
> function LinkUp($host,$username,$password)
> {
> $mysql_link=mysql_connect($host,$username,$passwor d);
> return $mysql_link;
> }
> ?>
>
> What have I done wrong? Please??
>



I am probably mistaken, but do you need to have "<?php" and "?>" in the
include file, as the file will be included within a section of code that's
already wrapped in the start/end php codes?



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 10:30 AM
strawberry
 
Posts: n/a
Default Re: Hiding MySQL username and password

On Mar 28, 4:23 pm, "Sean" <sean.anderson@[nospam]oakleafgroup.biz>
wrote:
> "Nosferatum" <John.Ola...@gmail.com> wrote in message
>
> news:1175027060.627223.175550@n59g2000hsh.googlegr oups.com...
>
>
>
> > Ok, I am a newbie. But now I have tried everything. My quest is to put
> > the MySQL host name, user name, password, databasename and table-name
> > in a separate file outside our web domain and call these variables via
> > include (into my PHP-file).
> > But it wont work! The path & diectories are all fine, the PHP script
> > works perfect (at last before I decided to move this critical
> > information).

>
> > This is the script:
> > <?php //starts here...
> > include ("/home/secret/protect/the_imported_mysqldata.inc");
> > $link=LinkUp($host,$username,$password)or die("Cant connect");
> > mysql_select_db($db_name)or die("cant choose db");

>
> > $sql="SELECT secret_variable FROM $tbl_name WHERE username='$username'
> > AND password='$password'";
> > $result=mysql_query($sql);

>
> > (and so on)

>
> > here is the included "the_imported_mysqldata.inc":
> > <?php
> > $host="the.secret.host";
> > $username="secret_as_stone";
> > $password="very_secret";
> > $db_name="secret_db";
> > $tbl_name="the_actual_table";

>
> > function LinkUp($host,$username,$password)
> > {
> > $mysql_link=mysql_connect($host,$username,$passwor d);
> > return $mysql_link;
> > }
> > ?>

>
> > What have I done wrong? Please??

>
> I am probably mistaken, but do you need to have "<?php" and "?>" in the
> include file, as the file will be included within a section of code that's
> already wrapped in the start/end php codes?


Yes you are - and yes you do! Correct me if I'm wrong but I think the
file server also needs permission to read the folder in which the
include is buried.
I know nothing whatsoever about security but I would have thought that
just putting the includes in a folder just outside the htdocs path
would be safe enough.

The folder would not need to be called anything like 'include'.
Likewise, I think the file can have any extension you care to give it

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 10:30 AM
John Nagle
 
Posts: n/a
Default Re: Hiding MySQL username and password

strawberry wrote:
> On Mar 28, 4:23 pm, "Sean" <sean.anderson@[nospam]oakleafgroup.biz>
> wrote:
>
>>"Nosferatum" <John.Ola...@gmail.com> wrote in message
>>
>>news:1175027060.627223.175550@n59g2000hsh.google groups.com...
>>
>>
>>
>>
>>>Ok, I am a newbie. But now I have tried everything. My quest is to put
>>>the MySQL host name, user name, password, databasename and table-name
>>>in a separate file outside our web domain and call these variables via
>>>include (into my PHP-file).


> I know nothing whatsoever about security

Um.

> but I would have thought that
> just putting the includes in a folder just outside the htdocs path
> would be safe enough.


The problem is that the web server, usually Apache, runs CGI programs
as user "nobody". It can't read your non-public files. If you
make the password file readable by any user,
anybody else on the machine can read it, which is terrible in shared
server environments.

John Nagle
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 10:30 AM
strawberry
 
Posts: n/a
Default Re: Hiding MySQL username and password

On Mar 28, 9:00 pm, John Nagle <n...@animats.com> wrote:
> strawberry wrote:
> > On Mar 28, 4:23 pm, "Sean" <sean.anderson@[nospam]oakleafgroup.biz>
> > wrote:

>
> >>"Nosferatum" <John.Ola...@gmail.com> wrote in message

>
> >>news:1175027060.627223.175550@n59g2000hsh.google groups.com...

>
> >>>Ok, I am a newbie. But now I have tried everything. My quest is to put
> >>>the MySQL host name, user name, password, databasename and table-name
> >>>in a separate file outside our web domain and call these variables via
> >>>include (into my PHP-file).

> > I know nothing whatsoever about security

>
> Um.
>
> > but I would have thought that

>
> > just putting the includes in a folder just outside the htdocs path
> > would be safe enough.

>
> The problem is that the web server, usually Apache, runs CGI programs
> as user "nobody". It can't read your non-public files. If you
> make the password file readable by any user,
> anybody else on the machine can read it, which is terrible in shared
> server environments.
>
> John Nagle


So what's the correct solution?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 10:30 AM
Peter H. Coffin
 
Posts: n/a
Default Re: Hiding MySQL username and password

On 28 Mar 2007 13:19:00 -0700, strawberry wrote:
> On Mar 28, 9:00 pm, John Nagle <n...@animats.com> wrote:
>> strawberry wrote:
>> > On Mar 28, 4:23 pm, "Sean" <sean.anderson@[nospam]oakleafgroup.biz>
>> > wrote:

>>
>> >>"Nosferatum" <John.Ola...@gmail.com> wrote in message

>>
>> >>news:1175027060.627223.175550@n59g2000hsh.google groups.com...

>>
>> >>>Ok, I am a newbie. But now I have tried everything. My quest is to put
>> >>>the MySQL host name, user name, password, databasename and table-name
>> >>>in a separate file outside our web domain and call these variables via
>> >>>include (into my PHP-file).
>> > I know nothing whatsoever about security

>>
>> Um.
>>
>> > but I would have thought that

>>
>> > just putting the includes in a folder just outside the htdocs path
>> > would be safe enough.

>>
>> The problem is that the web server, usually Apache, runs CGI programs
>> as user "nobody". It can't read your non-public files. If you
>> make the password file readable by any user,
>> anybody else on the machine can read it, which is terrible in shared
>> server environments.
>>
>> John Nagle

>
> So what's the correct solution?


Secure the web machine as well as possible, secure the databsae as well as
possible on a different machine, and make sure the functional ID (that
the CGI uses to connect to the database has only the access to the
database that is actually needed to accomplish the task at hand. In some
cases, that might be fun things things like the ID having only INSERT
access to some tables, and SELECT from others. Have other IDs used for
maintaining the database. That's the real bit: Your webserver should be
trusted no more than you can possibly managed.

--
14. The hero is not entitled to a last kiss, a last cigarette, or any other
form of last request.
--Peter Anspach's list of things to do as an Evil Overlord
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:39 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com