Skip to content

Commit a09f9f2

Browse files
authored
Merge pull request dokuwiki#4294 from dokuwiki/woltlab
Support Woltlab password hashes
2 parents cf88f10 + 07a871e commit a09f9f2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

_test/tests/inc/auth_password.test.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,8 @@ function test_verifyPassword_sha512_crypt() {
143143
}
144144
}
145145

146+
function test_verifyPassword_Woltlab()
147+
{
148+
$this->assertTrue(auth_verifyPassword('zQ9ZwsTvgufN', 'Bcrypt:$2y$12$ygz.4TeGn/NXEcXIE0pyge4lJyuSMqRdDPT5dW469lODb.HswSzjW'));
149+
}
146150
}

inc/PassHash.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ public function verify_hash($clear, $hash)
7979
$salt = $m[1];
8080
} elseif (preg_match('/^\$2([abxy])\$(.{2})\$/', $hash, $m)) {
8181
$method = 'bcrypt';
82-
$salt = $hash;
82+
$salt = $hash;
83+
} elseif (str_starts_with($hash, 'Bcrypt:$2')) {
84+
$method = 'woltlab';
85+
$salt = substr($hash, 7);
8386
} elseif (str_starts_with($hash, '{SSHA}')) {
8487
$method = 'ssha';
8588
$salt = substr(base64_decode(substr($hash, 6)), 20);
@@ -685,6 +688,21 @@ public function hash_bcrypt($clear, $salt = null, $compute = 10)
685688
return crypt($clear, $salt);
686689
}
687690

691+
/**
692+
* Password hashing method 'woltlab'
693+
*
694+
* Woltlab forums use a bcrypt hash with a custom prefix.
695+
*
696+
* @param $clear
697+
* @param $salt
698+
* @return string
699+
* @throws \Exception
700+
*/
701+
public function hash_woltlab($clear, $salt = null)
702+
{
703+
return 'Bcrypt:' . $this->hash_bcrypt($clear, $salt);
704+
}
705+
688706
/**
689707
* Password hashing method SHA-2
690708
*

0 commit comments

Comments
 (0)