I am working with site that is done with WordPress, and I need to add some parts that are outside WP, and to check user login, Logging users outside WP.
I tried with md5 of password but it’s not…
I tried this code:
require_once( 'wp-includes/class-phpass.php' );
$wp_hasher = new PasswordHash( 8, TRUE );
$password = "passwordhere";
$hashed_password = $wp_hasher->HashPassword( $password );
$encryptedpass = md5($hashed_password);
But this is only for first time creating password, and it’s always different.
I need code that can be used in this:
SELECT * FROM wp_customers WHERE email = "ccc@aaa.com" AND password = "<what goes here?>"
Is this possible anyhow?
Thanks.
Based on your other question … it sounds like you’re trying to validate a given plaintext password against what’s stored in the database. Here’s the function WordPress uses to do just that:
First, this plugin checks to see if the MD5 hash of the given password is the same as the stored (hashed) password for a user. It also checks to see if the PHPass hash of the given password is the same as the stored password for a user.
You can follow a similar pattern.
So let’s say you’re given a username and a password from the user and you want to validate them (
my_password_validation( $username, $password )
). You’ll use the given username to pull a hashed password from the database. Then you compare the hash of the given password to the stored value to see if it’s valid.Here’s some untested psuedocode:
If the password you pass in to the function hashes to the same as the stored value, the function will return true. Otherwise it will return false.
Looking at the comments you left on the other question, it seems like you have some other issues, though. To quote:
I can tell you right now that the password you’re getting from the database was not hashed using the PHPass utility. Those hashes will always resemble the
$P$B
starting because that’s what tells the system how it was hashed. PHPass is based on Blowfish which uses that kind of a prefix on encrypted strings.Your
fa063...
hash looks more like a standard MD5 hash … so if your MD5 hash of the plaintext doesn’t match, then I think you might have the wrong password.To answer your “how to I compare those two with MySQL” question … you don’t. MySQL is the data store … don’t do any business logic or comparison in the data store. Read data out, then use a PHP script to perform your comparison.
It’s very easy..
I had this problem and found out right on
wp_hash_password()
Finally, almost 10 years later. Found exact answer, what question is looking for.
You want do it with using Core PHP, right?
Here is the code for you!
First you need to add a class:
-> just copy it from
wp-includes/class-phpass.php
-> don’t worry. its written in core PHP.
You are almost done.
I made it here with trial and error. Now, its time for you to get to the point.
Happy coding!!!