WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For reasons I can't go into right now, I'm creating a form that will allow users to change their passwords for Wordpress by entering their current password and then entering the new password.

I want to do a databse lookup to see if the password they entered was the correct one already stored in the DB. However, in WP the passwords are encrypted somehow, so doing a simple SQL comparison on this column wont work. I tried using md5() on the password for the lookup but it doesn't seem to work either.

Here's my sql: SELECT ID, user_pass FROM wp_users WHERE ID = '$current_user->ID' AND user_pass = 'md5($currentpassword)' LIMIT 1

You can ignore most of this, but what I need to know is how I can do a comparison against the user_pass column?

I've tested this method above and it results in 0 rows returned - with or without the md5()

Please help!

Much appreciated.


share|improve this question

migrated from stackoverflow.com Jun 3 '11 at 4:16

This question came from our site for professional and enthusiast programmers.

Wordpress appears to have a built in function called wp_hash_password that will hash the given password and then you can compare it in the db.

share|improve this answer
Hi, thanks for your quick response. I have tried using the above function in place of where I had the MD5() function, but still no joy. Hmm. Any further ideas? Do you have a script you know that works? Thanks again. – Michael Giovanni Pumo Apr 6 '11 at 23:38
You cannot call wp_hash_password from MySQL. You must call it in PHP as per @Anthony's linked example. If you post full code someone might be able to help you. – Ciaran Apr 7 '11 at 7:24
@Ciaran I am running this SQL in a PHP WordPress template. Just using a standard PHP query where I check the number of rows returned. I'm not executing this SQL on the database itself or anywhere outside of PHP / WordPress. – Michael Giovanni Pumo Apr 7 '11 at 11:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.