I have a mysql user password with some special characters in it.

settings.php mentions the following information about special characters in your database url:

 * Database settings:
 *
 * Note that the $db_url variable gets parsed using PHP's built-in
 * URL parser (i.e. using the "parse_url()" function) so make sure
 * not to confuse the parser. If your username, password
 * or database name contain characters used to delineate
 * $db_url parts, you can escape them via URI hex encodings:
 *
 *   : = %3a   / = %2f   @ = %40
 *   + = %2b   ( = %28   ) = %29
 *   ? = %3f   = = %3d   & = %26

I used the hex codes to encode my password, but connecting was not possible:

Access is denied for user@localhost (Using Password: YES)

When i changed the connection string in includes/database.mysql.inc from

$connection = mysql_connect($url['host'], $url['user'], $url['pass'], TRUE) or die(mysql_error());
in
$connection = mysql_connect($url['host'], $url['user'], urldecode($url['pass']), TRUE) or die(mysql_error());

the problem was solved. Probably it is a good idea to do the same for username and host?

CommentFileSizeAuthor
#17 db_connect_urldecode.patch2.33 KBrkerr

Comments

serval-1’s picture

Version: 4.6.0 » 4.6.1

The bug is still there in the new 4.6.1 release :(

I changed the file database.mysql.inc to solve the problem:

After the lines

function db_connect($url) {
  $url = parse_url($url);

I added the following lines:

  $url['host'] = urldecode($url['host']);
  $url['user'] = urldecode($url['user']);
  $url['pass'] = urldecode($url['pass']);
  $url['path'] = urldecode($url['path']);

I think the problem also exists with other database systems, but I was not able to test this.

barryhawkins’s picture

Which specific characters are you trying to encode in your password? Using "%40" for the @ symbol resolved the issue for me; if you have the problem with particular symbols, perhaps I could test it here as well.

barryhawkins’s picture

My apologies; spoke too soon. After experimenting with some more, it does indeed still fail. I will check tomorrow to see if this has been included in 4.6.2; if not, I can attach a patch to this report. Not sure yet if that's how things are done here.

jmengle’s picture

Version: 4.6.1 » 4.6.2

I can confirm that I was having the same problem. I had an @ in a mysql password, and the "%40" encoding was not working, so I then tested a "%40" in the username. It definately was not being converted to a "@" symbol. I added these lines from above:

$url['host'] = urldecode($url['host']);
$url['user'] = urldecode($url['user']);
$url['pass'] = urldecode($url['pass']);
$url['path'] = urldecode($url['path']);

and everything worked just fine.

serval-1’s picture

Nice to see i'm not alone :D.

Anybody out there who is able to create a patch for this issue?

chx’s picture

If we would go this route then people with a percent sign in their db_url would get problems and what's worse it would break their update path, they would need to urlencode their passwords before an update. I am a bit reluctant to make this step.

serval-1’s picture

Well, there is a hex code for the percent sign itself too:

% = %25

So, when you have a percent sign in your username, you could still encode it.

zignit’s picture

Version: 4.6.2 » 4.6.3
Assigned: Unassigned » zignit
Priority: Normal » Critical

hey guys...first-timer here..
I was hoping to get a smooth install so I could see how drupal works, but Im having problems with my database/user-names.
I use the undersquare "_" and I can't seem to find the hex codes to encode. I only found the htmlcode for it.. "_" , but that doens't work...

Does someone know ??

Thanks in advanced!

serval-1’s picture

I think the underscore character has %5f as a hex encoding.
I tought that the underscore is a safe character for URL's. Is this not the case?

serval-1’s picture

Version: 4.6.3 » x.y.z

This issue is still there in the current CVS!

Really, anyone with any character like @, :, &, +,... in their database username or password will be unable to install and use Drupal!

I hope this will be patched before the 4.7 release

killes@www.drop.org’s picture

I think we can indeed fix this by adding a urldecode and telling everybody to add hexcode for % in the docs on update.php.

serval-1’s picture

Version: x.y.z » 4.6.4
Cvbge’s picture

I also think this is very important issue and should be fixed before 4.7

Cvbge’s picture

Version: 4.6.4 » x.y.z

Bumping.

If we really are not going to fix this for 4.7, then we should change the docs.

openmacnews’s picture

Title: Mysql Password with special symbols » Mysql *AND POSTGRESQL* Password with special symbols
Version: x.y.z » 4.7.0-beta3

i can verify that this is an issue with drupal 4.7b3 + pgsql 812 on OSX 10.4.4.

with my pg_hba.conf entry as:

hostssl drupaldb myuser 127.0.0.1 255.255.255.255 md5

using *any* special character (literal, "\"-escaped, or urlencoded) in $db_url's 'password' simply causes the connect to fail.

removing any/all suchh chars form password, everything's fine with plaintext/md5 pwds over encrypted SSL to DB.

richard

openmacnews’s picture

Title: Mysql *AND POSTGRESQL* Password with special symbols » Mysql & postgresql Password with special symbols

eek ... didn't mean to 'yell' ...

rkerr’s picture

Status: Active » Needs review
StatusFileSize
new2.33 KB

Patch against cvs for db_connect for MySQL, MySQLi, and PostgreSQL.

Cvbge’s picture

The best solution would be to use some other variable than $db_url
If $db_url is set, use old method, if $new_config is set - use new method
Very simple to implement and backward compatibile.
Would allow us to drop this ugly url-like syntax and add new features

Steven’s picture

Status: Needs review » Reviewed & tested by the community

IMO this is commit ready. The number of people who have such special characters in their username/password should be tiny and it's simple enough to fix.

chx’s picture

Commit if you want, but it'll break the update path for those who have a percent sign in their password. Given the even smaller number of those, I think this one is good to go.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Chris Johnson’s picture

Version: 4.7.0-beta3 » 4.7.0-beta4
Status: Fixed » Active

Well, indeed, it busted my Drupal install when I upgraded to 4.7. I had a plus sign in my MySQL password.

Guess what? That's a perfectly valid URL, too. Plus signs are only URL delimiters when they occur after the question mark ? sign in the path to the right of the hostname.

My site worked for 2 years, and then blew up when I installed 4.7 because this patch tossed the plus sign with urldecode().

My host uses autogenerated MySQL passwords and they can include plus signs. How many people do you suppose are going to get screwed by this? It's especially hard to figure out because the admin knows the database parameters are right because they were working and were not changed with the install. Because of that, the site admin is unlikely to read the comments in the settings.php file and notice that the plus sign needs to be hex encoded. Instead, that admin is going to contact their host and ask WTF is wrong with the database connection.

In fact, the standard for URLs specifically says + signs are valid and are not to be encoded. See here: http://www.ietf.org/rfc/rfc1738.txt

This fix breaks that standard.

PHP's parse_url() handles it correctly and returns the + sign.

Cvbge’s picture

You should encode "+" as settings.php says. UPGRADE.txt should be updated to reflect this.

serval-1’s picture

I think the url-like syntax for connecting to the database is not the way to go.

  • The hex-encoding is confusing
  • The url-format looks scary for those who have never composed a URL themselves
  • The url-syntax adds no extra value over using different variables for the parameters

My proposal is to make url-syntax an deprecated option, and to use something like this in the new settings.php file:

$dbuser = ""; /* enter your database username between the quotes */
$dbpassword = ""; /* enter your database username password between the quotes */
$dbhost = "localhost"; /* change the parameter according to your database settings */
$dbport = ""; /* enter the port of your database server here */
Steven’s picture

If the + is an issue, we should use rawurlencode() and rawurldecode(). The non-raw versions are meant for query string arguments really.

moshe weitzman’s picture

i agree that the url syntax confuses people for no good reason (that I can think of). separate fields makes better since to me.

dries’s picture

I'm OK with seperate fields if that is going to fix a bunch of problems. Use $db_ not $db.

dries’s picture

Changing that setting will complicate the upgrade process though. People will be forced to edit their settings.php before they can even attempt to upgrade... Maybe this should be put on hold for 4.8?

moshe weitzman’s picture

Priority: Critical » Normal

i also am inclined to wait on this. workarounds are available so i set to normal priority.

killes@www.drop.org’s picture

Version: 4.7.0-beta4 » x.y.z

moving

chx’s picture

Title: Mysql & postgresql Password with special symbols » Do not use URL syntax for database settings
stevenpatz’s picture

Version: x.y.z » 6.x-dev
Status: Active » Postponed (maintainer needs more info)
moshe weitzman’s picture

Version: 6.x-dev » 7.x-dev
Status: Postponed (maintainer needs more info) » Postponed

seems like noone cares anymore. reopen if i am wrong.

webchick’s picture

Status: Postponed » Closed (won't fix)

Marking won't fix. We have an installer now that takes care of this for you, so there should very rarely need to be a reason to go in and putz with settings.php.