Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-20-2004, 09:04 AM
|
#1
|
LQ Newbie
Registered: Apr 2004
Posts: 3
Rep:
|
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...
|
|
|
04-20-2004, 09:46 AM
|
#2
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
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.
|
|
|
04-20-2004, 10:22 AM
|
#3
|
LQ Newbie
Registered: Apr 2004
Posts: 3
Original Poster
Rep:
|
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.
|
|
|
04-20-2004, 12:31 PM
|
#4
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
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.
|
|
|
04-22-2004, 03:19 PM
|
#5
|
Senior Member
Registered: Feb 2003
Location: The Arctic
Distribution: Fedora, Debian, OpenSuSE and Android
Posts: 1,820
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 04:57 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|