Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / user / authentication / password / algorithm / Argon2.class.php
CommitLineData
84d4fb1b 1<?php
a9229942 2
84d4fb1b 3namespace wcf\system\user\authentication\password\algorithm;
a9229942 4
84d4fb1b 5use wcf\system\user\authentication\password\IPasswordAlgorithm;
6
7/**
8 * Implementation of Argon2.
9 *
a9229942
TD
10 * @author Joshua Ruesweg
11 * @copyright 2001-2020 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\User\Authentication\Password\Algorithm
14 * @since 5.4
84d4fb1b 15 */
a9229942
TD
16final class Argon2 implements IPasswordAlgorithm
17{
18 private const OPTIONS = [
19 'memory_cost' => 65536,
20 'time_cost' => 4,
21 'threads' => 1,
22 ];
23
24 /**
25 * @inheritDoc
26 */
27 public function verify(string $password, string $hash): bool
28 {
29 return \password_verify($password, $hash);
30 }
31
32 /**
33 * @inheritDoc
34 */
35 public function hash(string $password): string
36 {
37 return \password_hash($password, \PASSWORD_ARGON2I, self::OPTIONS);
38 }
39
40 /**
41 * @inheritDoc
42 */
43 public function needsRehash(string $hash): bool
44 {
45 return \password_needs_rehash($hash, \PASSWORD_ARGON2I, self::OPTIONS);
46 }
84d4fb1b 47}