Skip to content

Commit 7a8a36a

Browse files
authored
Merge pull request dokuwiki#4388 from xi/unusable-password
allow to set unusable password
2 parents dbc152d + b21b793 commit 7a8a36a

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

_test/tests/inc/auth_password.test.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ function test_verifySelf($method, $hash) {
7373
$this->assertTrue(auth_verifyPassword('foo' . $method, $hash));
7474
}
7575

76+
/**
77+
* @dataProvider hashes
78+
* @param $method
79+
* @param $hash
80+
*/
81+
function test_verifyUnusable($method, $hash) {
82+
$hash = auth_cryptPassword(null, $method);
83+
$this->assertFalse(auth_verifyPassword(null, $hash));
84+
}
85+
7686
function test_bcrypt_self() {
7787
$hash = auth_cryptPassword('foobcrypt', 'bcrypt');
7888
$this->assertTrue(auth_verifyPassword('foobcrypt', $hash));

inc/auth.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,8 @@ function act_resendpwd()
13191319
* If the selected method needs a salt and none was given, a random one
13201320
* is chosen.
13211321
*
1322+
* You can pass null as the password to create an unusable hash.
1323+
*
13221324
* @author Andreas Gohr <[email protected]>
13231325
*
13241326
* @param string $clear The clear text password
@@ -1329,6 +1331,11 @@ function act_resendpwd()
13291331
function auth_cryptPassword($clear, $method = '', $salt = null)
13301332
{
13311333
global $conf;
1334+
1335+
if ($clear === null) {
1336+
return DOKU_UNUSABLE_PASSWORD;
1337+
}
1338+
13321339
if (empty($method)) $method = $conf['passcrypt'];
13331340

13341341
$pass = new PassHash();
@@ -1354,6 +1361,10 @@ function auth_cryptPassword($clear, $method = '', $salt = null)
13541361
*/
13551362
function auth_verifyPassword($clear, $crypt)
13561363
{
1364+
if ($crypt === DOKU_UNUSABLE_PASSWORD) {
1365+
return false;
1366+
}
1367+
13571368
$pass = new PassHash();
13581369
return $pass->verify_hash($clear, $crypt);
13591370
}

inc/defines.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
define('DOKU_MEDIA_INUSE', 4);
6666
define('DOKU_MEDIA_EMPTY_NS', 8);
6767

68+
/**
69+
* Unusable password hash
70+
* @file inc/auth.php
71+
*/
72+
define('DOKU_UNUSABLE_PASSWORD', '!unusable');
73+
6874
/**
6975
* Mail header constants
7076
*

0 commit comments

Comments
 (0)