Problem
- The current password hashing library is a custom fork of phpass.
- It has to be maintained by Drupal. Drupal should not be in the business of developing/maintaining a password hashing library.
- The hashing algorithm is 100% custom. 0% interoperability.
- The next time we upgrade our hash algorithm or iterations count, we have to deal with it all over again. PHP's password_hash() has forward-upgrading built in to its design
Proposed resolution
The following description refers to MR !3245 (branch 1845004-phpass-module
). A less ambitious proposal can be found in MR !3181 (branch 1845004-replace-custom-password-
).
- Replace the custom password hashing library with PHP 5.5's
password_hash()
. - Use
password_hash()
with default parameters (i.e.$algo = PASSWORD_DEFAULT
and$options = []
). As a result, Drupal follows improvements to the defaults made in subsequent PHP releases automatically. - Sites with special needs may specify
$algo
and$options
by overriding the arguments of thepassword
service. - Extract the existing hashing mechanism to validate passwords of user entities created with Drupal prior to version 10.1.x into a separate core module (
phpass
). - Enable the
phpass
core module in apost_update
hook for all existing sites. - Add
phpass
as a dependency tomigrate_drupal
. This ensures that passwords migrated from an existing site can be verified without any further action. - Keep the
phpass
core module disabled for new sites. - Deprecate
\Drupal\Core\Password\PhpassHashedPassword
(but not the code moved to thephpass
module).
Note: Whether it is acceptable to disable the phpass
module is highly individual for each existing website. Some sites have thousands of active users and breaking their logins all at the same time will result in a huge support nightmare. On other sites there is only a small circle of admin accounts. Migrating their passwords to the PHP password_hash()
format might be accomplished in a few weeks without any manual intervention and the phpass
module can be disabled without causing any problems in a subsequent deployment.
Drupal should deprecated the phpass
module in some future release and move it to contrib. That decision could be taken based on actual usage numbers - which are expected to decline over time.
Remaining tasks
None.
API changes
- A new password service (
Drupal\Core\Password\PhpPassword
) is introduced which essentially wrapspassword_hash()
,password_verify()
andpassword_needs_rehash
). - The implementation of
Drupal\Core\Password\PhpassHashedPassword
is moved to a newphpass
module. - A deprecated subclass is left at
Drupal\Core\Password\PhpassHashedPassword
and removed in Drupal 11.0
Data model changes
None.