How to expire all wordpress user passwords instantly?

So I own an article directory website and recently a lot of bots have signed up and started posting spam. (I approve posts prior to publication)

I’ve added a captcha to the user registration page now but for the users that are already registered I want to make their passwords expire so they have to set new ones and obviously the bots won’t be able to do this.

Read More

I’ve tried multiple plugins with no success. I don’t really know what to do. I have over 1800 users so going through them 1 by 1 is not an option.

Would appreciate this a lot!

Thank you!

Related posts

Leave a Reply

1 comment

  1. Some underlying functionality borrowed from http://wordpress.org/extend/plugins/auto-expire-passwords/ , and tweaked. Untested, but along the lines of what you are looking for, so YMMV.

    function custom_forced_password_reset( $user ) {
        update_user_meta( $user->ID, 'password_was_force_reset', true );
    }
    add_action( 'password_reset', 'custom_forced_password_reset' );    
    
    // Ensure all new register users have the flag set
    function custom_forced_password_user_register($user_id){
        update_user_meta( $user_id, 'password_was_force_reset', true );
    }
    add_action( 'user_register', 'custom_forced_password_user_register', 10, 1 );
    
    function custom_log_in_check( $user, $username, $password ) {
        if ( is_wp_error( $user ) )
            return $user;
    
        // Check we're dealing with a WP_User object
        if ( ! is_a( $user, 'WP_User' ) )
            return $user;
    
        // This is a log in which would normally be succesful
        $user_id = $user->data->ID;
    
    
        $reset = get_user_meta( $user_id, 'password_was_force_reset', false );
        if ( empty( $reset ) || $reset == false ) {
                $user = new WP_Error( 'authentication_failed', sprintf('<strong>ERROR</strong>: You must <a href="%s">reset your password</a>.', site_url( 'wp-login.php?action=lostpassword', 'login' ) ) );
        }
    
        return $user;
    }
    add_filter( 'authenticate', 'custom_log_in_check', 30, 3 );