Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Michael.

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.

add comment

1 Answer 1

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
1  
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
add comment

Your Answer

 
discard

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.