1 | <?php |
||
13 | class DjangoPassword implements IPassword { |
||
14 | /** |
||
15 | * @var string The hash method to use when hashing passwords. |
||
16 | */ |
||
17 | public $hashMethod; |
||
18 | |||
19 | /** |
||
20 | * Initiailize an instance of the {@link DjangoPassword} class. |
||
21 | * |
||
22 | * @param string $hashMethod The hasm method used to hash the passwords. |
||
23 | */ |
||
24 | 5 | public function __construct($hashMethod = 'crypt') { |
|
27 | |||
28 | /** |
||
29 | * Generate a random salt that is compatible with {@link crypt()}. |
||
30 | * |
||
31 | * @return string|null Returns the salt as a string or **null** if the crypt algorithm isn't known. |
||
32 | */ |
||
33 | 4 | protected function generateCryptSalt() { |
|
54 | |||
55 | /** |
||
56 | * Hashes a plaintext password. |
||
57 | * |
||
58 | * @param string $password The password to hash. |
||
59 | * @return string Returns the hashed password. |
||
60 | * @throws \Exception Throws an exception when the hash method is invalid. |
||
61 | */ |
||
62 | 8 | public function hash($password) { |
|
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | 6 | public function needsRehash($hash) { |
|
98 | |||
99 | /** |
||
100 | * Check to make sure a password matches its stored hash. |
||
101 | * |
||
102 | * @param string $password The password to verify. |
||
103 | * @param string $hash The stored password hash. |
||
104 | * @return bool Returns `true` if the password matches the stored hash. |
||
105 | */ |
||
106 | 8 | public function verify($password, $hash) { |
|
121 | } |
||
122 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: