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'm looking to advise a user that they should change their password from the default generated one that was emailed to them.

Is there a function or hook that will tell me if the user is running the default password?

share|improve this question
add comment

2 Answers

The following will tell you if the user has updated the password generated by WP on registration for a user with ID $user_id:

if ( ! get_user_option('default_password_nag', $user_id) ) {
    //then the user has changed the default password
} else {
    //the default password has not been changed
}

If you want to send an email @goldenapples' answer is good (replacing the logic in user_password_check for checking whether the password has been changed with my logic.)

share|improve this answer
    
So I did a very simple test and it seems to be persistent. If the user has or has not changed the password it shows "it works" $user = get_user_by( 'id', $user_id ); if ( ! get_user_option('default_password_nag', $user_id) ) { echo "it works"; } –  Zach Shallbetter Aug 19 '11 at 23:28
    
Are you able to look at the wp_usermeta table and see search for the default_password_nag key? WordPress deletes this key when a user changes his password, so get_user_option('default_password_nag', $user_id) would return null. From what you say in your comment it looks like the key isn't being added on registration. So I'd say look at the registration plugin you're using. –  Chris Carson Aug 19 '11 at 23:44
    
So there are no database entries with default_password_nag and when looking at the plugin I referenced above I'm finding either update_user_option( $user_id, "default_password_nag", false, true ); or update_user_option( $user_id, "default_password_nag", true, true ); –  Zach Shallbetter Aug 20 '11 at 0:00
    
Any thoughts on this Chris? –  Zach Shallbetter Aug 30 '11 at 18:10
    
If there's no default_password_nag key in wp_usermeta after you register as a new user, then your registration plugin is probably overriding the default WordPress functionality. –  Chris Carson Aug 30 '11 at 18:26
add comment

The question is, how are you setting the default passwords?

That said, I think it would be perfectly reasonable to trigger a scheduled action in say, a weeks time from the date you create the user. It should be pretty simple, something like this would probably do the trick:

add_action( 'user_register', 'check_in_a_week' );

function check_in_a_week( $user_id ) {
    $user = get_user_by( 'id', $user_id );
    wp_schedule_single_event( 'user_password_check', 7*24*60*60, 
        array( 'user_id' => $user_id, 'user_pass' => $user->user_pass ) );
}

function user_password_check( $args ) {
    extract( $args );
    $user = get_user_by( 'id', $user_id );
    if ( $user->user_pass == $user_pass ) {

        // send them mail...
    }
}

(I didn't test it yet, so I'm not sure if it will stand up to real use. Treat it as pseudo-code for what you're trying to do.)

share|improve this answer
    
I'm using registration-plus-redux (filedropper.com/register-plus-redux). I believe, however, that the generated password is done by WordPress, not the plugin. –  Zach Shallbetter Aug 19 '11 at 22:57
add comment

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.