Problem/Motivation
There is an @todo note in core.services.yml to increase the number of iterations used when hashing passwords for every Drupal core release.
We last increased this value almost a decade ago in #1203852: Increase hashing iterations for D7 and D8.. It was noted at the time that we should do this "every version" assuming we are on 18-24 month release cycles, but also really this is all about execution time, and single core CPU clocks have still not really increased since then.
Proposed resolution
Either increase the password iterations log2 value from 16 (to 17 or 18), or remove the todo.
Remaining tasks
Benchmark how long a password hash takes on a modern CPU to decide whether we should change this or not.
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
Issue fork drupal-3110670
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3110670-increase-password-hashing
changes, plain diff MR !2014
Comments
Comment #2
cilefen commentedWhy doesn't core use password_hash?
Comment #3
xjmHeh...
We'd do this in a minor release. It was even backported to a patch release of D7. ;)
Comment #4
andypostThe todo needs fix because it doesn't mention minor or major version should affect it
https://git.drupalcode.org/project/drupal/-/blob/9.0.x/core/core.service...
Comment #5
jungleI'd suggest making the value configurable giving the right to the site builders/owners. For example: adding an item to
settings.phpIn core, just set a default value as the recommended count by the community.
following are my considerations:
a) For firewall-protected internal web applications, the security is less important probably. The value could be less than the recommended one.
b) For some security-sensitive web applications, they may want to sacrifice the time/UE to enhance the security so that they may want to set a higher count value than the recommended one.
If they set a value lower than the recommended one, a warning could be given on the status page if it is necessary.
Comment #9
xjmComment #10
mcdruid commentedYeah, it should nowadays. Linking #1845004: Replace custom password hashing library with PHP password_hash().
As far as this issue goes, we can do benchmarks but IIUC the point of increasing the hashing iterations is to make cracking Drupal password hashes more costly.
A typical Drupal site doesn't need to - for example - go through a word list trying to crack hashes. (Although there is a module for that :).
I don't think the cost of the hashing matters particularly for a Drupal site (within reason).
Having said all that I did some benchmarking and the results were interesting - tl;dr we should not increase this iteration count too much.
Methodology
Incremenent the count, clear cache and time setting one new password using drush.
n.b. don't set real passwords like this - there's far too little entropy (the value actually shouldn't make any difference to the benchmark).
This is on an Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz. Pretty sure this is single-threaded.
Results
...I gave up there.
Conclusion
I think it's okay to keep incrementing the count for D9 and the next few major releases, but we probably don't want to increase the count to the point where hashing a single password takes tens of seconds (or more) on typical hardware.
Comment #12
andypostBenchmarks are above, but still needs work to pass tests
Comment #13
andypostComment #15
andypostBetter title
Comment #16
mfbI did some quick benchmarking to see where things are at and found that password hashing is approximately twice as fast on a newish laptop compared to a ~10-year-old, budget-grade server. And the laptop was actually running around a third of its max clock rate - maxing out one core was not enough to get it to switch to a higher clock rate.
Based on this, I'd say increasing to 17 iterations is very reasonable - it's a little slow on old hardware but still under 100 milliseconds. And those hosting on better hardware could reasonably go higher than 17. Of course, I'd hope that phpass will be phased out any day now in the related issue, i.e. fingers crossed this issue doesn't need to be worked on?
Newish laptop (AMD Ryzen 7 PRO 6850U):
Old server (Intel Xeon E3-1265L v3):
Test script is as follows:
Comment #17
mfbComment #18
mfbI think this issue should be closed in favor of #1845004: Replace custom password hashing library with PHP password_hash() - but setting to needs review until that happens
Comment #19
smustgrave commentedDo agree this can be closed in favor of #1845004: Replace custom password hashing library with PHP password_hash() that one seems like a closer. I'll move over credit.