Timeout on password change

pennymachines
w3 User
w3 User
Posts: 115
Joined: Mon Feb 06, 2017 9:51 pm

Timeout on password change

Post by pennymachines »

While diagnosing timeouts on password changes I found two things I'd like to report. Both are reproducible on my site.

ENVIRONMENT
- WordPress Multisite (subdirectory sites), WordPress [version, 6.9.1 or later], PHP [version]
- wp-w3all-phpbb-integration [version] (the latest available as of 16 Nov 2026), phpBB [version]
- Shared hosting with a slow CPU (page boot takes about 4-6 s, each SMTP send about 2 s), behind Cloudflare
- Other relevant plugins: Simple Membership (front-end profile edits), Wordfence, Post SMTP

ISSUE 1: PHP warning, wrong variable in create_phpBB_user_wpms()

Host error log (12 Nov 2026 06:46:03 UTC):
PHP Warning: Attempt to read property "user_login" on string in .../wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php on line 3849

In the "WP MS MU" section, create_phpBB_user_wpms($username_id_object = '', $user_email = '', $key = '', $meta = '', $user = '') contains:

} elseif(is_object( $username_id_object )){
$username = $user->user_login;
$user_email = $user->user_email;

In this branch $user is still its default value '' (the object is in $username_id_object), which causes the warning. $username and $user_email then stay empty, so the function returns at the "empty($username) OR !is_email($user_email)" check and no phpBB user is created on that path. I believe the branch should read $username_id_object->user_login and $username_id_object->user_email. (I matched the warning to this code from the section around line 3849, so please confirm the exact line in your source.)

ISSUE 2: the wp_check_password override is slow, and the cost multiplies when it is called in a loop

Symptom: changing a password through a front-end profile form took 200-300 s with w3all active and ended in a Cloudflare 524 (the password itself was saved). With the cause below removed, the same request takes about 13 s.

Cause: Wordfence's option "Check password strength on profile update" runs wfScanEngine::scanUserPassword() from wordfence::profileUpdateAction (profile_update hook). That calls wp_check_password() repeatedly (86 times in my tests) against the user's stored hash. With w3all active, each call took roughly 2.2-3.6 s on my host. Instrumentation of the profile-save request with w3all active showed:

- stack for each pass: apply_filters@wp_w3all.php:572 < wp_check_password@wordfence/lib/wfScanEngine.php:1681 < wfScanEngine::scanUserPassword@wordfence/lib/wordfenceClass.php:7214 < wordfence::profileUpdateAction
- 86 x "SELECT * FROM wp_users WHERE ID = ?" and 86 x "SELECT user_password, user_email FROM phpbb_users WHERE LOWER(user_email) = ?"
- w3all connection: 94 queries, 9.1-9.5 s in total; wpdb: about 300 queries, 1.4-1.5 s in total
- gaps of 2.2-3.6 s between the end of the WordPress user query and the check_password filter at wp_w3all.php:572
- total request time 222-299 s

With the Wordfence hook removed: w3all connection 8 queries, 0.12 s in total, and the whole request took 12.9 s.

Wordfence is therefore the amplifier, but the per-call cost is in the override. The database time does not account for the gaps, so I suspect the time is spent before the apply_filters at line 572 (hash verification is my guess, but I have not confirmed it; I noticed bcrypt cost 12 is used for temporary passwords in create_phpBB_user_wpms, and I do not know the cost of the stored hashes).

Questions and suggestions:
1. What does the override do before line 572, and is about 2.5 s per call expected on a slow host?
2. Could it skip the phpBB lookup (and the other work) when the call is not part of a login, or cache the phpBB row per request, so that repeated calls for the same user are cheap?
3. The lookup uses WHERE LOWER(user_email) = ?. As far as I know phpBB indexes user_email_hash rather than user_email, so this would be a full table scan (up to about 1.1 s per query on my site). Looking the user up by user_email_hash, which w3all already computes in w3all_phpbb_email_hash(), might be much faster.

Workaround in place: I have turned off the Wordfence option above.

I can supply the full timing traces if that would help.

Thank you again Alessio for all your work on this plugin.
User avatar
axew3
w3all User
w3all User
Posts: 3110
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Skype: axewww

Re: Timeout on password change

Post by axew3 »

Thank you for the report all will be fixed within tomorrow asap as i find the time to do so releasing next version.

But on fly:

Like others, we could fix the password check fired too times (and it is also 2 time into normal WP MUMS, still not tested on default WP) just doing this (it is coming as fix into next version, and it may could be fixed in several different ways, may this is the faster and simpler):

File wp_w3all.php on line 468 start the
function wp_check_password($password, $hash, $user_id = '') {

and it start like this:


[code]function wp_check_password($password, $hash, $user_id = '') {

// wp do not allow char \ on password
// phpBB allow \ char on password

global $wpdb,$wp_hasher,$w3all_add_into_phpBB_after_confirm,$w3all_add_user_in_phpbb_onlogin_yn;
$password = trim(str_replace(chr(0), '', $password));
$check = false;
$hash_x_wp = $hash;

# Include Custom code for others plugins login actions if there is a custom_login.php file
if (file_exists(ABSPATH.'wp-content/plugins/wp-w3all-custom/custom_login.php')){
include(ABSPATH.'wp-content/plugins/wp-w3all-custom/custom_login.php');
}
....
....
....[/code]

change into

[code]function wp_check_password($password, $hash, $user_id = '') {

if ( defined('W3ALL_CK_PASS') ) return;

// wp do not allow char \ on password
// phpBB allow \ char on password

global $wpdb,$wp_hasher,$w3all_add_into_phpBB_after_confirm,$w3all_add_user_in_phpbb_onlogin_yn;
$password = trim(str_replace(chr(0), '', $password));
$check = false;
$hash_x_wp = $hash;

# Include Custom code for others plugins login actions if there is a custom_login.php file
if (file_exists(ABSPATH.'wp-content/plugins/wp-w3all-custom/custom_login.php')){
include(ABSPATH.'wp-content/plugins/wp-w3all-custom/custom_login.php');
}

define('W3ALL_CK_PASS', true);
....
....
....[/code]


While about
correct user addition in phpBB upon registration on WP MUMS
the
private static function create_phpBB_user_wpms
on file class.wp.w3all-phpbb.php should be substituted with this:

Code: Select all

private static function create_phpBB_user_wpms($username_id_object = '', $user_email = '', $key = '', $meta = '', $user = ''){

  global $w3all_user_email_hash,$w3all_phpbb_connection,$wpdb,$phpbb_config,$w3all_config,$w3all_phpbb_lang_switch_yn,$w3all_add_into_spec_group,$w3all_phpbb_user_deactivated_yn,$w3all_add_into_phpBB_after_confirm;

   // skip, if 'create phpBB user after account confirmation' option enabled
   // if this option active, the user will be added into phpBB only after his first successful login
   // via 'wp_authenticate' -> w3_check_phpbb_profile_wpnu() <-> self::create_phpBB_user($user, 'add_u_phpbb_after_login')
   // avoid if admin action
   //if( $w3all_add_into_phpBB_after_confirm == 1 && $action != 'add_u_phpbb_after_login' && !current_user_can( 'create_users' ) )
   if( $w3all_add_into_phpBB_after_confirm == 1 && !current_user_can( 'create_users' ) )
    {
      return; // due to the above, if not admin, return here
    }


   if(!empty($user->user_login)){
    $username = $user->user_login;
    $user_email = $user->user_email;
    $user_pass = $user->user_pass;
   } elseif( !empty($username_id_object->data) ) {
     $username = $username_id_object->data->user_login;
     $user_email = $username_id_object->data->user_email;
     $user_pass = $username_id_object->data->user_pass;
   } elseif(is_numeric($username_id_object)){
     $user = get_user_by( 'ID', $username_id_object );
     if(!empty($user)){
      $username = $user->user_login;
      $user_email = $user->user_email;
      $user_pass = $user->user_pass;
     }
   } else {
     $username = $username_id_object;
     $user_email = $user_email;
    }

   if( empty($username) OR !is_email($user_email) ){ // see wp_w3all.php // add_action( 'init', 'w3all_network_admin_actions' );
     return;
    }

   $u_exist = self::ck_phpbb_user($username, $user_email);

   if(!empty($u_exist)){
     temp_wp_w3_error_on_update();
    }

   $default_dateformat = $phpbb_config["default_dateformat"];
   $default_lang = $phpbb_config["default_lang"];
   $phpbb_version = substr($phpbb_config["version"], 0, 3);

  $phpbb_group = $w3all_phpbb_connection->get_results("SELECT * FROM ".$w3all_config["table_prefix"]."ranks
   RIGHT JOIN ".$w3all_config["table_prefix"]."groups ON ".$w3all_config["table_prefix"]."groups.group_rank = ".$w3all_config["table_prefix"]."ranks.rank_id
   AND ".$w3all_config["table_prefix"]."ranks.rank_min = '0'
   AND ".$w3all_config["table_prefix"]."groups.group_id = '$w3all_add_into_spec_group'",ARRAY_A);

 if(!empty($phpbb_group)){
  $urank_id_a = array();
   foreach($phpbb_group as $kv){
    foreach($kv as $k => $v){
     if($k == 'group_id' && $v == $w3all_add_into_spec_group){
      $urank_id_a = $kv;
     }
   }}
 if (empty($urank_id_a)){
   foreach($phpbb_group as $kv){
    foreach($kv as $k => $v){
    if($k == 'rank_special' && $v == 0){
    $urank_id_a = $kv;
    goto this1; // break to the first found (seem to be the default phpBB behavior)
    }
   }}
 }
this1:
if ( empty($urank_id_a) ){
  $rankID = 0;
  $group_color = '';
 } else {
if ( empty($urank_id_a['rank_id']) ){
  $rankID = 0; $group_color = $urank_id_a['group_colour'];
  } else {
  $rankID = $urank_id_a['rank_id']; $group_color = $urank_id_a['group_colour'];
}}

} // END if(!empty($phpbb_group) OR ! $phpbb_group){
else { $rankID = 0; $group_color = ''; }

      if(!isset($default_lang) OR empty($default_lang)){ $wp_lang_x_phpbb = 'en'; }
       else { $wp_lang_x_phpbb = $default_lang; }

     // maybe to be added as option
     // setup gravatar by default into phpBB profile for the user when register in WP
     $uavatar = $avatype = '';
     //$uavatar = get_option('show_avatars') == 1 ? $wpu->user_email : '';
     //$avatype = (empty($uavatar)) ? '' : 'avatar.driver.gravatar';

     $u = $phpbb_config["cookie_name"].'_u';

        if ( isset($_COOKIE[$u]) && preg_match('/[^0-9]/',$_COOKIE[$u]) ){
                die( "Clean up cookie on your browser please!" );
         }

     $phpbb_u = isset($_COOKIE[$u]) ? $_COOKIE[$u] : '';
      // only need to fire when user do not exist on phpBB already, and/or user is an admin that add an user manually
  if ( $phpbb_u < 2 OR !empty($phpbb_u) && current_user_can( 'manage_options' ) === true ) {

      $phpbb_user_type = $w3all_phpbb_user_deactivated_yn == 1 ? 1 : 0;

      //$phpbb_user_type = 0; // modified // set to 1 as deactivated on phpBB on WP MSMU except for admin action (but it is not what needed, since activation link set to user if admin action via https://localhost/wp5/wp-admin/network/user-new.php)

      if(current_user_can( 'create_users' )){
        $phpbb_user_type = 0;
      }

      self::w3all_phpbb_email_hash($user_email);


     if( isset($user_pass) ){
        $wpup = $user_pass;
      }
       else {
       $wpup = substr(str_shuffle(md5(time()) . 'ABCKDEFGLJZ'), 0, rand(8,16)); // a temp pass to be updated after signup finished
       $wpup = password_hash($wpup, PASSWORD_BCRYPT,['cost' => 12]);
      }

      $wpur = time();
      $wpul = $username;

   if(!current_user_can( 'create_users' )) {
      // password fix
      // password of the just created WP user, when 'insert_user_meta' fire, may require reset to what need to be
      $wpu_db_utab = (is_multisite()) ? WPW3ALL_MAIN_DBPREFIX . 'users' : $wpdb->prefix . 'users';
       $query = $wpdb->prepare( "UPDATE $wpu_db_utab SET user_pass = %s WHERE user_email = %s",
      $wpup, $user_email );
      $wpdb->query($query);
    } else {
        $wpup = $user_pass; // if admin action, add the pass of this user, it exist at this point in this case
      }

      $wpue = $user_email;
      $time = time();

      $wpunn = strtolower($wpul);

     // if added as newely registered user, the user need to be also added into Registered Group
     // and as user new 1 into users tab (to be correctly removed from newbie group when promoted based on posts)
      $user_new = 0;
      if($w3all_add_into_spec_group == 7){
        $w3all_add_into_spec_group = 2;
        $w3all_add_into_spec_group_def = true;
        $user_new = 1;
      }

        // phpBB 3.3.0> 4 >
          $query_insert_users = $w3all_phpbb_connection->prepare(
           "INSERT INTO " . $w3all_config["table_prefix"] . "users (user_id, user_type, group_id, user_regdate, username, username_clean, user_password, user_email, user_lang, user_colour, user_avatar, user_avatar_type, user_new) VALUES (%s, %d, %d, %d, %s, %s, %s, %s, %s, %s, %s, %s, %d)",
           '', (int)$phpbb_user_type, (int)$w3all_add_into_spec_group, (int)$wpur, $wpul, $wpunn, $wpup, $wpue, $wp_lang_x_phpbb, $group_color, $uavatar, $avatype, (int)$user_new
          );
          $w3all_phpbb_connection->query($query_insert_users);

       $phpBBlid = $w3all_phpbb_connection->insert_id; // memo: pass only assigned vars on queries using this, or will return null

    if($phpBBlid > 2){

       $w3all_phpbb_connection->query("INSERT INTO ".$w3all_config["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('$w3all_add_into_spec_group','$phpBBlid','0','0')");

       // if added as newely registered user, then the user need to be also added as newbie (group id 7)
      if(isset($w3all_add_into_spec_group_def)){ // add into 7, newely
       $w3all_phpbb_connection->query("INSERT INTO ".$w3all_config["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('7','$phpBBlid','0','0')");
      }

       $w3all_phpbb_connection->query("UPDATE ".$w3all_config["table_prefix"]."config SET config_value = config_value + 1 WHERE config_name = 'num_users'");

       $newest_member = $w3all_phpbb_connection->get_results("SELECT * FROM ".$w3all_config["table_prefix"]."users WHERE user_id = (SELECT Max(user_id) FROM ".$w3all_config["table_prefix"]."users) AND group_id != '6'");
       $uname = $newest_member[0]->username;
       $uid   = $newest_member[0]->user_id;

       $w3all_phpbb_connection->query("UPDATE ".$w3all_config["table_prefix"]."config SET config_value = '$wpul' WHERE config_name = 'newest_username'");
       $w3all_phpbb_connection->query("UPDATE ".$w3all_config["table_prefix"]."config SET config_value = '$uid' WHERE config_name = 'newest_user_id'");
    }
 }

}
I note that at first login after creation, the user in phpBB will log ok, on wordpress instead the first login fail and the second goes ok, even if hashes and pass are equal! I will check why tomorrow. I did not tested Simple Membership, please let know what you may still find out not working.
User avatar
axew3
w3all User
w3all User
Posts: 3110
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Skype: axewww

Re: Timeout on password change

Post by axew3 »

We go to rewrite all step by step.
2. Could it skip the phpBB lookup (and the other work) when the call is not part of a login, or cache the phpBB row per request, so that repeated calls for the same user are cheap?
3. The lookup uses WHERE LOWER(user_email) = ?. As far as I know phpBB indexes user_email_hash rather than user_email, so this would be a full table scan (up to about 1.1 s per query on my site). Looking the user up by user_email_hash, which w3all already computes in w3all_phpbb_email_hash(), might be much faster.
About point 2: there is already a way linked into the how to page, but it can be done better,
we'll improve it
https://www.axew3.com/w3/2025/05/phpbb- ... on-update/

About point 3: no, phpBB4 do not use anymore the email hash (if i am not wrong this is the reason of the switch into the plugin code also): Searching for an email or an email hash that are both indexed into SQL do not really make a big difference.



Ps why Simple Membership plugin's guys do not fix the
PHP Deprecated: File Theme without footer.php is <strong>deprecated</strong> since version 3.0.0 with no alternative available. Please include a footer.php template in your theme. in D:/HTDOCS/wp-mums/wp-includes/functions.php on line 6260
wrapping the code of the file simple-wp-membership.php into a

Code: Select all

add_action('after_setup_theme', function() {
....
});
Is there any reason for somebody? It is very bad to have my text editor asking me to reload the always opened error Php file that change each time the Wp fire heartbeat, due to warnings that the plugin throws continuously.
pennymachines
w3 User
w3 User
Posts: 115
Joined: Mon Feb 06, 2017 9:51 pm

Re: Timeout on password change

Post by pennymachines »

Thank you Alessio.

I'll await the next update, as I've already reduced the password reset process to about 15 seconds on my setup with the Wordfence option off, plus a few other tweaks.

Cheers!
User avatar
axew3
w3all User
w3all User
Posts: 3110
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Skype: axewww

Re: Timeout on password change

Post by axew3 »

Ciao David!
Version 3.2.5 will be released to sites in about 6 hours but it can be already downloaded from the plugin page
https://wordpress.org/plugins/wp-w3all- ... tegration/


3.2.5 has been released to fix all the important above reported

It has been tested working fine all around on default and multisite and also with Simple Membership flows.
The login will now run only once.

Code: Select all


= 3.2.5 =
* Release Date: 17 Nov 2026
* Fixed: Correctly add users to phpBB when they register on WordPress Multisite (changed `private static function create_phpBB_user_wpms` in class.wp.w3all-phpbb.php).
* Fixed: Prevent redundant wp_check_password() calls across WordPress and plugin hooks on login (changed `wp_check_password` in wp_w3all.php).

Waiting for next issue! ...in the way to release the new w3myPQ!
Please follow report any problem you may found and thank to you!
User avatar
axew3
w3all User
w3all User
Posts: 3110
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Skype: axewww

Re: Timeout on password change

Post by axew3 »

Ps David if you can please report again now, after the update, hooks that are still running more times if it is possible (with cloudflare).