Skip to content

Commit dfaf074

Browse files
committed
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.
1 parent 4d2a091 commit dfaf074

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

_test/tests/inc/auth_password.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function hashes() {
2424
array('kmd5', 'a579299436d7969791189acadd86fcb716'),
2525
array('djangomd5', 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158'),
2626
array('djangosha1', 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678'),
27-
2827
);
2928

3029
if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) {
@@ -81,6 +80,7 @@ function test_bcrypt_self() {
8180

8281
function test_verifyPassword_fixedbcrypt() {
8382
$this->assertTrue(auth_verifyPassword('foobcrypt', '$2a$12$uTWercxbq4sjp2xAzv3we.ZOxk51m5V/Bv5bp2H27oVFJl5neFQoC'));
83+
$this->assertTrue(auth_verifyPassword('lemmybcrypt12hash', '$2b$12$zMBuY6QAGXuT6elIbadavO1JTI6DfaGe1MpfBthG/nt6mkodwmKAi'));
8484
}
8585

8686
function test_verifyPassword_nohash() {

inc/PassHash.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function verify_hash($clear, $hash)
7777
} elseif (preg_match('/^md5\$(.{5})\$/', $hash, $m)) {
7878
$method = 'djangomd5';
7979
$salt = $m[1];
80-
} elseif (preg_match('/^\$2(a|y)\$(.{2})\$/', $hash, $m)) {
80+
} elseif (preg_match('/^\$2([abxy])\$(.{2})\$/', $hash, $m)) {
8181
$method = 'bcrypt';
8282
$salt = $hash;
8383
} elseif (str_starts_with($hash, '{SSHA}')) {

0 commit comments

Comments
 (0)