PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.5.1
Defender Security – Malware Scanner, Login Security & Firewall v5.5.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / thecodingmachine / safe / generated / password.php

password.php in Defender Security – Malware Scanner, Login Security & Firewall 5.5.1, at vendor/thecodingmachine/safe/generated/password.php

127 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Safe;
4
5 use Safe\Exceptions\PasswordException;
6
7 /**
8 * password_hash creates a new password hash using a strong one-way hashing
9 * algorithm. password_hash is compatible with crypt.
10 * Therefore, password hashes created by crypt can be used with
11 * password_hash.
12 *
13 *
14 *
15 *
16 * PASSWORD_DEFAULT - Use the bcrypt algorithm (default as of PHP 5.5.0).
17 * Note that this constant is designed to change over time as new and stronger algorithms are added
18 * to PHP. For that reason, the length of the result from using this identifier can change over
19 * time. Therefore, it is recommended to store the result in a database column that can expand
20 * beyond 60 characters (255 characters would be a good choice).
21 *
22 *
23 *
24 *
25 * PASSWORD_BCRYPT - Use the CRYPT_BLOWFISH algorithm to
26 * create the hash. This will produce a standard crypt compatible hash using
27 * the "$2y$" identifier. The result will always be a 60 character string.
28 *
29 *
30 *
31 *
32 * PASSWORD_ARGON2I - Use the Argon2i hashing algorithm to create the hash.
33 * This algorithm is only available if PHP has been compiled with Argon2 support.
34 *
35 *
36 *
37 *
38 * PASSWORD_ARGON2ID - Use the Argon2id hashing algorithm to create the hash.
39 * This algorithm is only available if PHP has been compiled with Argon2 support.
40 *
41 *
42 *
43 *
44 *
45 *
46 *
47 * salt (string) - to manually provide a salt to use when hashing the password.
48 * Note that this will override and prevent a salt from being automatically generated.
49 *
50 *
51 * If omitted, a random salt will be generated by password_hash for
52 * each password hashed. This is the intended mode of operation.
53 *
54 *
55 *
56 * The salt option has been deprecated as of PHP 7.0.0. It is now
57 * preferred to simply use the salt that is generated by default.
58 *
59 *
60 *
61 *
62 *
63 * cost (integer) - which denotes the algorithmic cost that should be used.
64 * Examples of these values can be found on the crypt page.
65 *
66 *
67 * If omitted, a default value of 10 will be used. This is a good
68 * baseline cost, but you may want to consider increasing it depending on your hardware.
69 *
70 *
71 *
72 *
73 *
74 *
75 *
76 * memory_cost (integer) - Maximum memory (in kibibytes) that may
77 * be used to compute the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_MEMORY_COST.
78 *
79 *
80 *
81 *
82 * time_cost (integer) - Maximum amount of time it may
83 * take to compute the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_TIME_COST.
84 *
85 *
86 *
87 *
88 * threads (integer) - Number of threads to use for computing
89 * the Argon2 hash. Defaults to PASSWORD_ARGON2_DEFAULT_THREADS.
90 *
91 *
92 *
93 *
94 * @param string $password The user's password.
95 *
96 * Using the PASSWORD_BCRYPT as the
97 * algorithm, will result
98 * in the password parameter being truncated to a
99 * maximum length of 72 characters.
100 * @param int|string|null $algo A password algorithm constant denoting the algorithm to use when hashing the password.
101 * @param array $options An associative array containing options. See the password algorithm constants for documentation on the supported options for each algorithm.
102 *
103 * If omitted, a random salt will be created and the default cost will be
104 * used.
105 * @return string Returns the hashed password.
106 *
107 * The used algorithm, cost and salt are returned as part of the hash. Therefore,
108 * all information that's needed to verify the hash is included in it. This allows
109 * the password_verify function to verify the hash without
110 * needing separate storage for the salt or algorithm information.
111 * @throws PasswordException
112 *
113 */
114 function password_hash(string $password, $algo, array $options = null): string
115 {
116 error_clear_last();
117 if ($options !== null) {
118 $result = \password_hash($password, $algo, $options);
119 } else {
120 $result = \password_hash($password, $algo);
121 }
122 if ($result === false) {
123 throw PasswordException::createFromPhpError();
124 }
125 return $result;
126 }
127