1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) Phauthentic (https://github.com/Phauthentic) |
5
|
|
|
* |
6
|
|
|
* Licensed under The MIT License |
7
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
8
|
|
|
* Redistributions of files must retain the above copyright notice. |
9
|
|
|
* |
10
|
|
|
* @copyright Copyright (c) Phauthentic (https://github.com/Phauthentic) |
11
|
|
|
* @link https://github.com/Phauthentic |
12
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types=1); |
16
|
|
|
|
17
|
|
|
namespace Phauthentic\PasswordHasher; |
18
|
|
|
|
19
|
|
|
use PasswordHash; |
|
|
|
|
20
|
|
|
use RuntimeException; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Wordpress Password Hasher |
24
|
|
|
* |
25
|
|
|
* The wordpress password hasher is an adapter for the `\PasswordHash` class |
26
|
|
|
* which is part of Wordpress. You can copy the file class-phpass.php to your |
27
|
|
|
* project, rename the namespace or do whatever is needed to make it available |
28
|
|
|
* in your project and / or namespace. |
29
|
|
|
* |
30
|
|
|
* @link https://github.com/WordPress/WordPress/blob/master/wp-includes/class-phpass.php |
31
|
|
|
*/ |
32
|
|
|
class WordpressPasswordHasher extends AbstractPasswordHasher |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Wordpress Passwordhasher |
36
|
|
|
* |
37
|
|
|
* @var \PasswordHash |
38
|
|
|
*/ |
39
|
|
|
protected $wpPasswordHash; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
*/ |
44
|
|
|
public function __construct(?PasswordHash $passwordHash = null) |
45
|
|
|
{ |
46
|
|
|
$this->wpPassWordHash = $passwordHash; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Gets the instance of the WP PasswordHash class |
51
|
|
|
* |
52
|
|
|
* @return \PasswordHash |
53
|
|
|
*/ |
54
|
|
|
public function getPassWordHash() |
55
|
|
|
{ |
56
|
|
|
if (empty($this->wpPassWordHash)) { |
57
|
|
|
$this->wpPasswordHash = new PasswordHash(8, true); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->wpPassWordHash; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Generates password hash. |
65
|
|
|
* |
66
|
|
|
* @param string|array $password Plain text password to hash or array of data |
67
|
|
|
* required to generate password hash. |
68
|
|
|
* @return string Password hash |
69
|
|
|
*/ |
70
|
|
|
public function hash(string $password): string |
71
|
|
|
{ |
72
|
|
|
return $this->getPassWordHash()->hashPassword($password); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Check hash. Generate hash from user provided password string or data array |
77
|
|
|
* and check against existing hash. |
78
|
|
|
* |
79
|
|
|
* @param string $password Plain text password to hash or data array. |
80
|
|
|
* @param string $hashedPassword Existing hashed password. |
81
|
|
|
* @return bool True if hashes match else false. |
82
|
|
|
*/ |
83
|
|
|
public function check(string $password, string $hashedPassword): bool |
84
|
|
|
{ |
85
|
|
|
return $this->getPassWordHash()->checkPassword($password, $hashedPassword); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths