Skip to main content
Login Join
Snippet · PHP

Force Strong Passwords on User Registration

Shared by Jainil Nagar · June 1, 2026 · @user_profile_update_errors

22 views
Back to Snippets
add_action( 'user_profile_update_errors', 'wpfolks_enforce_strong_password', 10, 3 );
function wpfolks_enforce_strong_password( $errors, $update, $user ) {
    if ( isset( $user->user_pass ) ) {
        $password = $user->user_pass;
        if (
            strlen( $password ) < 10 ||
            ! preg_match( '/[A-Z]/', $password ) ||
            ! preg_match( '/[0-9]/', $password ) ||
            ! preg_match( '/[^a-zA-Z0-9]/', $password )
        ) {
            $errors->add(
                'weak_password',
                __( 'Password must be at least 10 characters and include an uppercase letter, a number, and a special character.', 'textdomain' )
            );
        }
    }
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments