1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus framework.
7: *
8: * (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Password;
15:
16: interface HashInterface
17: {
18: public const int MINIMUM_PASSWORD_LENGTH = 8;
19: public const int MAXIMUM_PASSWORD_LENGTH = 4096;
20:
21: /**
22: * Creates a new password hash using a strong one-way hashing algorithm.
23: *
24: * @param array{
25: * cost?: int,
26: * iterations?: int,
27: * length?: int,
28: * opslimit?: int,
29: * memlimit?: int,
30: * memory_cost?: int,
31: * threads?: int,
32: * time_cost?: int,
33: * } $options
34: *
35: * @throws HashException
36: */
37: public function hash(#[\SensitiveParameter] string $password, array $options = []): string;
38:
39: /**
40: * Checks if the given hash matches the given options.
41: *
42: * @param array{
43: * cost?: int,
44: * iterations?: int,
45: * length?: int,
46: * opslimit?: int,
47: * memlimit?: int,
48: * memory_cost?: int,
49: * threads?: int,
50: * time_cost?: int,
51: * } $options
52: */
53: public function needsRehash(string $hash, array $options = []): bool;
54:
55: /**
56: * Verifies that a password matches a hash.
57: */
58: public function verify(#[\SensitiveParameter] string $password, string $hash): bool;
59:
60: /**
61: * Checks if the hash driver can be used.
62: */
63: public function valid(): bool;
64:
65: /**
66: * Checks if the password is without defects before hashing.
67: */
68: public function isValidPassword(#[\SensitiveParameter] string $password): bool;
69: }
70: