Bug: when adding CMS user with a profile, get a fatal error when passwords get verified for strength
The error:
TypeError: trim(): Argument #1 (closed) ($string) must be of type string, array given in trim() (line 1111 of /var/www/vhosts/code.on.ca/httpdocs/core/modules/user/user.module).
If a Backdrop site has "Reject weak passwords" setting enabled, then it will check the password with user_password_policy_validate()
. This is required to recreate the error.
CRM_Utils_System_Backdrop::createUser()
is passing the passwords as an array, which is the same as the Drupal 7 version. It's not clear why since both items in the array "pass1" and "pass2" are assigned the same field, instead of the confirmation password as well. As far as I can tell Drupal 7 does nothing with it, thus no errors. (Unless it is need for a contrib module). At any rate Backdrop only needs the main password field for validation (CiviCRM already checks that the two password fields match.)
The quick fix:
$form_state['input']['pass'] = ['pass1' => $params['cms_pass'], 'pass2' => $params['cms_pass']];
should be:
$form_state['input']['pass'] = $params['cms_pass'];
But on top of that it would be good to do the password verification in CRM_Core_BAO_CMSUser::formRule()
similar to the username and email verification. Otherwise, the user will only see Backdrop complain after the profile is submitted and it redirects to the home page.
PR to follow