0

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)

Thanks.

0

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
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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