Support b and x variants for bcrypt hashes

Prompted by https://forum.dokuwiki.org/d/22108-authpdo-with-postgres-and-lemmy/3

As stated on https://stackoverflow.com/a/36225192

> there is no difference between 2, 2a, 2x, 2y, and 2b. If you wrote your
> implementation correctly, they all output the same result.
This commit is contained in:
Andreas Gohr 2024-03-13 15:44:23 +01:00
parent 4d2a091249
commit dfaf0747ed
2 changed files with 2 additions and 2 deletions

View File

@ -24,7 +24,6 @@ class auth_password_test extends DokuWikiTest {
array('kmd5', 'a579299436d7969791189acadd86fcb716'),
array('djangomd5', 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158'),
array('djangosha1', 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678'),
);
if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) {
@ -81,6 +80,7 @@ class auth_password_test extends DokuWikiTest {
function test_verifyPassword_fixedbcrypt() {
$this->assertTrue(auth_verifyPassword('foobcrypt', '$2a$12$uTWercxbq4sjp2xAzv3we.ZOxk51m5V/Bv5bp2H27oVFJl5neFQoC'));
$this->assertTrue(auth_verifyPassword('lemmybcrypt12hash', '$2b$12$zMBuY6QAGXuT6elIbadavO1JTI6DfaGe1MpfBthG/nt6mkodwmKAi'));
}
function test_verifyPassword_nohash() {

View File

@ -77,7 +77,7 @@ class PassHash
} elseif (preg_match('/^md5\$(.{5})\$/', $hash, $m)) {
$method = 'djangomd5';
$salt = $m[1];
} elseif (preg_match('/^\$2(a|y)\$(.{2})\$/', $hash, $m)) {
} elseif (preg_match('/^\$2([abxy])\$(.{2})\$/', $hash, $m)) {
$method = 'bcrypt';
$salt = $hash;
} elseif (str_starts_with($hash, '{SSHA}')) {