I tried doing something like this:
$user = $wpdb->get_row('
SELECT *
FROM ' . $wpdb->users . '
WHERE user_pass = "' . wp_hash_password('password') . '"'
);
But the wp_hash_password
function generates a different string from the one in the database, is it possible?
What I’d like to do is have a custom form in my template that just asks for a password (think of it like the username/pwd screen to the WP admin area without the username) so I’d hash whatever the user inputs, compare it with my DB and if it matches take that user and log him in.
Password is not unique all the time.
According to
worst password
statistics,password
is the most used Password of all time.I’m pretty sure some of your users too use that password.
So multiple rows will contain the same hash. Hence its not possible.
By the way, this is a weird question.
Per the comments I’m going to answer a paraphrased question – “How to make a login form which shows only the password field in most cases”.
The answer is to store the user name in a very long term cookie (a year?) every time the user logins.
Now in you PHP code you can check if the cookie is set and show or hide the user name field in your form.
No warranties for this code, but I think it is the best approximation to what you want without sacrificing security and messing with the WordPress user system.
Here’s what I ended up doing in case someone else need a similar functionality: