Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security risk in storing SQL login info in PHP code?

First time reader, first time poster (woo!)

So I've been implementing my login scripts for an informal website. Not likely to be compromised, but just to be safe, I'd like to ask if there's a security risk in having my MySQL database login stored in plaintext in the php code.

As far as I know, the code itself is parsed by Apache, so the end-user doesn't see it (just the output), which would mean it should be safe to keep... but I'd like a second opinion.

Summary: Accessing database through mysql_connect, mysql_select_db, mysql_query. Login info stored in local variables defined at each iteration of the script, and (I think) dumped once script terminates.

Security vulnerability?

like image 335
Julian H. Lam Avatar asked Jun 13 '09 20:06

Julian H. Lam


People also ask

Is it safe to store password in PHP file?

PHP provides a native password hashing API that safely handles both hashing and verifying passwords in a secure manner.

What is PHP in cyber security?

PHP: PHP language is a server-side programming language that is used to generate websites. Powering most of the best 10 million websites, PHP is the usual powerful server-side language on the web. Experience in PHP, therefore, will allow you to understand how to protect against invaders.


1 Answers

You could also consider moving the username/password combination to a seperate configuration file that lives outside the webroot. Make sure that place is not directly accessible from the webserver side.

That way, if for some reason the webserver decides not to execute PHP files anymore you don't lose the account information to the database server.

As an added bonus, if you use anything that makes a copy of the .php file (editors, SVN or whatever) in the webroot, you don't risk anyone getting around the .php execution.

like image 137
ylebre Avatar answered Oct 05 '22 08:10

ylebre