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

I need to add a passkey to each user, so I decided to just giving the user password that value and use WP functionality to store it/retrieve it.

So now I need to find what user that password belongs to, so a single field would be necessary to identify him, rather than asking for email AND passkey.

How do I find a user by password? I know what is stored in the DB are not passwords, but something else, but I don't care. We won't have enough users for getting two with the same MD5 (or whatever is stored)


share|improve this question

The user password (stored as an MD5 hash) can be retrieved like so:

$users = get_users();

foreach ( $users as $user ) {
    $password = $user->user_pass;

Assuming you have some known value for passkey, you can hash it and compare it to each user's password:

$passkey = 'somestring';

$hashed_passkey = md5( $passkey );

$users = get_users();

foreach ( $users as $user ) {
    if ( $user->user_pass == $hashed_passkey ) {
        // We have a match!
        // Do something
share|improve this answer

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.