Lines Matching defs:hash

10  * This class implements various mechanisms used to hash passwords
19 * Verifies a cleartext password against a crypted hash
21 * The method and salt used for the crypted hash is determined automatically,
29 * @param string $hash Hash to compare against
32 public function verify_hash($clear, $hash)
39 if (str_starts_with($hash, 'U$')) {
42 $hash = substr($hash, 1);
45 $len = strlen($hash);
46 if (preg_match('/^\$1\$([^\$]{0,8})\$/', $hash, $m)) {
50 } elseif (preg_match('/^\$apr1\$([^\$]{0,8})\$/', $hash, $m)) {
54 } elseif (preg_match('/^\$S\$(.{52})$/', $hash, $m)) {
58 } elseif (preg_match('/^\$P\$(.{31})$/', $hash, $m)) {
62 } elseif (preg_match('/^\$H\$(.{31})$/', $hash, $m)) {
66 } elseif (preg_match('/^pbkdf2_(\w+?)\$(\d+)\$(.{12})\$/', $hash, $m)) {
70 } elseif (preg_match('/^PBKDF2(SHA\d+)\$(\d+)\$([[:xdigit:]]+)\$([[:xdigit:]]+)$/', $hash, $m)) {
74 } elseif (preg_match('/^sha1\$(.{5})\$/', $hash, $m)) {
77 } elseif (preg_match('/^md5\$(.{5})\$/', $hash, $m)) {
80 } elseif (preg_match('/^\$2([abxy])\$(.{2})\$/', $hash, $m)) {
82 $salt = $hash;
83 } elseif (str_starts_with($hash, 'Bcrypt:$2')) {
85 $salt = substr($hash, 7);
86 } elseif (str_starts_with($hash, '{SSHA}')) {
88 $salt = substr(base64_decode(substr($hash, 6)), 20);
89 } elseif (str_starts_with($hash, '{SMD5}')) {
91 $salt = substr(base64_decode(substr($hash, 6)), 16);
92 } elseif (preg_match('/^:B:(.+?):.{32}$/', $hash, $m)) {
95 } elseif (preg_match('/^\$(5|6)\$(rounds=\d+)?\$?(.+?)\$/', $hash, $m)) {
99 } elseif (preg_match('/^\$(argon2id?)/', $hash, $m)) {
103 return password_verify($clear, $hash);
110 } elseif ($len == 41 && $hash[0] == '*') {
114 $salt = $hash;
117 $salt = substr($hash, 0, 2);
123 if (\hash_equals($newhash, $hash)) {
179 * @param string $clear The clear text to hash
202 * @param string $clear The clear text to hash
222 * @param string $clear The clear text to hash
224 * @param string $magic The hash identifier (apr1 or 1)
269 * @param string $clear The clear text to hash
282 * @param string $clear The clear text to hash
295 * @param string $clear The clear text to hash
310 * @param string $clear The clear text to hash
327 * @param string $clear The clear text to hash
351 * @param string $clear The clear text to hash
365 * least 18 bytes. You can pass the crypted hash as salt.
367 * @param string $clear The clear text to hash
384 * Initial hash is repeatedly rehashed with same password.
385 * Any salted hash algorithm supported by PHP hash() can be used. Salt
399 * @param string $algo The hash algorithm to be used
400 * @param string $clear The clear text to hash
402 * @param string $magic The hash identifier (P or H)
426 $hash = hash($algo, $salt . $clear, true);
428 $hash = hash($algo, $hash . $clear, true);
433 $count = strlen($hash);
436 $value = ord($hash[$i++]);
439 $value |= ord($hash[$i]) << 8;
444 $value |= ord($hash[$i]) << 16;
465 * @param string $clear The clear text to hash
467 * @param string $magic The hash identifier (P or H)
480 * Implements Drupal salted sha512 hashs. Drupal truncates the hash at 55
487 * @param string $clear The clear text to hash
489 * @param string $magic The hash identifier (S)
523 * @param string $clear The clear text to hash
541 * @param string $clear The clear text to hash
562 * @param string $clear The clear text to hash
564 * @param array $opts ('algo' => hash algorithm, 'iter' => iterations)
589 $hash = hash_pbkdf2($algo, $clear, hex2bin($salt), $iter, 0);
590 return "PBKDF2$prefixalgo\$$iter\$$salt\$$hash";
599 * @param string $clear The clear text to hash
601 * @param array $opts ('algo' => hash algorithm, 'iter' => iterations)
625 $hash = base64_encode(hash_pbkdf2($algo, $clear, $salt, $iter, 0, true));
626 return "pbkdf2_$algo\$$iter\$$salt\$$hash";
630 * Alias for djangopbkdf2 defaulting to sha256 as hash algorithm
632 * @param string $clear The clear text to hash
645 * Alias for djangopbkdf2 defaulting to sha1 as hash algorithm
647 * @param string $clear The clear text to hash
666 * A full hash should be given as salt (starting with $a2$) or this
670 * @param string $clear The clear text to hash
694 * Woltlab forums use a bcrypt hash with a custom prefix.
716 * @param string $clear The clear text to hash
770 * @param string $clear The clear text to hash
784 * Uses php's own password_hash function to create argon2i password hash
787 * @link https://www.php.net/manual/de/function.password-hash.php
789 * @param string $clear The clear text to hash
803 * Uses php's own password_hash function to create argon2id password hash
806 * @link https://www.php.net/manual/de/function.password-hash.php
808 * @param string $clear The clear text to hash
828 * @link http://php.net/manual/en/function.hash-hmac.php#93440