Password is null if user has never logged in which causes PHP 8 warning

Created on 24 August 2022, about 2 years ago
Updated 22 January 2023, almost 2 years ago

Problem/Motivation

When

  • a user has never logged in and attempts to log in or
  • users are primarily logging in via SSO. (In that case, they do not/may not have a password for local login.)

these PHP 8 warnings are a result:

Deprecated function: substr(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Password\PhpassHashedPassword->check() (line 223 of core/lib/Drupal/Core/Password/PhpassHashedPassword.php).

Deprecated function: substr(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Password\PhpassHashedPassword->check() (line 234 of core/lib/Drupal/Core/Password/PhpassHashedPassword.php).

This is the reason:

Hint: the `pass`column in `users_field_data` database table is nullable

Function authenticate in UserAuth.php line 50 has this:
if ($this->passwordChecker->check($password, $account->getPassword())) {

If the user has never logged in, getPassword() returns null. That sends null to the $hash parameter in checkI() in PhpassHashedPassword.php. It then tries to send that to substr() causing the warning as passing null where it's expecting a string is deprecated.

Steps to reproduce

Attempt to log in with an account that has never logged in.

Proposed resolution

I'm thinking we can simply check if getPassword() returns null and skip out if it does. I think this is an edge case because the account isn't being created by the user so there is no password set. In that case, it wouldn't be possible for them to log in without requesting a password reset, anyway.

Remaining tasks

Make the patch (in progress).

User interface changes

API changes

Data model changes

None.

🐛 Bug report
Status

Needs work

Version

10.1

Component
User system 

Last updated about 12 hours ago

Created by

🇺🇸United States michelle Wisconsin, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024