Jump to content

Encrypting MySQL passwords and accessing


RooZ

Recommended Posts

Hello,

I have a website which I'm the "global admin" but others contribute to the coding as well. The only problem with this is the MySQL password which is in plain text on each page. What I'm hoping to do is to be able to have the password md5'd or similar, but that's where I hit a snag and I'm not too sure how to get MySQL to accept the password in md5 form.

Is it possible to have the password fully encrypted, or will I have to use another tactic?

Cheers

Link to comment
Share on other sites

Okay, I don't think I was very clear, what I mean is:

if (!@mysql_connect("localhost", "root", "thispassword")) { [..]

"thispassword" is in plain text, which I don't want. I was hoping it would be possible to get the md5 hash, so it was:

if (!@mysql_connect("localhost", "root", "f6a0f3655b26fe4e058a59b4757f6019")) { [..]

And still be able to connect to the database.

Cheers

Link to comment
Share on other sites

If someone has access to your PHP files, you should be able to trust them with your MySQL info....

 

 

As far as I know, the password has to be passed to mysql_connect in plain text....

 

You could always do mysql_connect(,, decrypt(<hash>)), but someone could simply do echo decrypt(<hash>).

 

Unless there's a way to send mysql the encrypted password and have it know what it is (I'm gonna go Googling in a sec), it has to be plain text in your PHP files.

Link to comment
Share on other sites

If someone has access to your PHP files, you should be able to trust them with your MySQL info....

That's true, but I've come across a few sites where the Apache conf got messed or corrupted up and .php files we're printed entirely as a .txt, which is a bit worrying.

Might be a bit excessive, but I rather be secure than hacked :)

Link to comment
Share on other sites

You could get a commercial script encrypter, and that would encrypt everything....  A php script encoded with Zend Guard for example looks like gibberish....  But, php encrypting things are expensive.

 

I doubt your httpd.conf is going to get corrupted if that's your only fear.

 

Also, your mysql could be set to only accept local connections, meaning unless someone could upload php or use something like SSH, you would be fine MySQL wise even if someone did find out your password.

 

I assumed you were trying to hide the password from people who were supposed to have access to your PHP sources.

Link to comment
Share on other sites

Any form data is used in inside of a php script is accessible.

 

Example:

 

$hash = '9asd9390af8972D9q34K';
do_something(decrypt_hash($hash));

 

Obviously if someone could get in the PHP file they could just echo the return from decrypt_hash x.x.

 

If it has to be passed as plain text to mysql_connect, there's no way to stop someone from seeing the password.

 

Right as I said that I got an idea.....

 

You could use a class, located out of the access levels of anyone who would view php files....  In this class, the hash would be decrypted, but passed inside of the class, so no one could see it outside....

 

 

Lemme code an example...

Link to comment
Share on other sites

Let's pretend the siteroot is /html/, and that you're the only person with FTP access to /.

 

/secret_mysql.php

class secret_mysql {

public function connect($host, $user, $pass, $db) {
	return mysql_connect($host, $user, $this->decrypt($pass), $db);
}

private function decrypt($pass) {
	return base64_decode($pass);
}

/* public function makehash($pass) {
	return base64_encode($pass);
} */
//example hash making fucntion

}

 

/html/example.php

require '../secret_mysql.php';
$c = new secret_mysql;
//lets pretend for this example that the mysql username is root and the password is 'corbin'
$link = $c->connect('localhost', 'root', 'Y29yYmlu', 'somedb'); //base64_encode return of 'corbin', the example password

 

That would work, and at no point could anyone output the password even if they could include and use secret_mysql.php.

 

The only problem with that (besides the obvious base64_encode as the encryption), is that someone could do this:

 

echo file_get_contents('../secret_mysql.php');

 

And then run it somewhere else showing the output of decrypt.....

 

 

Hmmmm....  I guess it's really not possible to protect data from its owner script lol ;p.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.