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.

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.

share|improve this question

1 Answer 1

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

 
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.