1

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?

2 Answers 2

4

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.)

5
  • 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"; } Aug 19, 2011 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. Aug 19, 2011 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 ); Aug 20, 2011 at 0:00
  • Any thoughts on this Chris? Aug 30, 2011 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. Aug 30, 2011 at 18:26
0

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.)

1

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.