LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 04-20-2004, 09:04 AM   #1
Wibble
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
PHP > MySQL connection password security question


I am using PHP to connect to a MySQL database using the following code:

$conn = mysql_connect("localhost", "root", "password") or die(mysql_error());

This works just fine but I am concerned about the security implications of having the password in the source code.

Is there a better method of achieving this that doesn't require the password to be in the source code?

Thanks in advance...
 
Old 04-20-2004, 09:46 AM   #2
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Why are you using root to access mySQL? It would be a LOT safer to create a new mySQL user that only has privileges for the tables that PHP needs to access. That would at least mitigate any potential problems.

By the way, PHP is server side. I'm not sure that a user can see the PHP source code unless you are distributing it as a separate file rather than serving it as a web page.
 
Old 04-20-2004, 10:22 AM   #3
Wibble
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Hangdog42
Why are you using root to access mySQL? It would be a LOT safer to create a new mySQL user that only has privileges for the tables that PHP needs to access. That would at least mitigate any potential problems.
You are quite right, the code in use does, as you suggest, use a different username configured for the purpose.

I'm surprised that Linux doesn't offer a system like ODBC DSN connections that removes the need for passwords in the source code.
 
Old 04-20-2004, 12:31 PM   #4
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Quote:
I'm surprised that Linux doesn't offer a system like ODBC DSN connections that removes the need for passwords in the source code.

I'm going to step WAY out of my depths here, but are you sure it doesn't? This really isn't a Linux problem, this is actually a mySQL problem since it is the mySQL username and password you have to hard code, not the Linux ones.

This is where I get out of my depths: You probably need to do a bit of mySQL research and see if it does support a system like ODBC DSN. Just a little googling around suggests to me that there is a driver called myODBC that might do the trick. I haven't investigated enough to be sure however. And if mySQL doesn't work the way you need it to, maybe another database like PostgreSQL or Firebird will.
 
Old 04-22-2004, 03:19 PM   #5
Pcghost
Senior Member
 
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820

Rep: Reputation: 46
The way we keep it a little safer is to use connection documents stored outside the docroot. A simple "require_once('connect.php')" appears in all our database enabled scripts. That way, if the script is cracked and the source revealed, they don't get connection details, only the database structure from the queries.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php-mysql connection pb abd_bela Debian 2 09-23-2005 04:07 AM
Security risks of php based mysql queries TigerOC Linux - Security 5 04-10-2005 07:30 AM
MYSQL paranoia security prohibits PHP to use database ? Dark Carnival Debian 1 01-08-2005 10:33 AM
Remote Mysql Connection in PHP ElementNine Programming 2 05-03-2004 04:24 PM
php / mysql connection problem . MikeFoo1 Programming 3 05-02-2004 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration