Lines Matching refs:salt

21      * The method and salt used for the crypted hash is determined automatically,
35 $salt = '';
38 //determine the used method and salt
48 $salt = $m[1];
52 $salt = $m[1];
56 $salt = $m[1];
60 $salt = $m[1];
64 $salt = $m[1];
69 $salt = $m[3];
73 $salt = $m[3];
76 $salt = $m[1];
79 $salt = $m[1];
82 $salt = $hash;
85 $salt = substr(base64_decode(substr($hash, 6)), 20);
88 $salt = substr(base64_decode(substr($hash, 6)), 16);
91 $salt = $m[1];
94 $salt = $m[3];
111 $salt = $hash;
114 $salt = substr($hash, 0, 2);
119 $newhash = $this->$call($clear, $salt, $magic);
127 * Create a random salt
129 * @param int $len The length of the salt
134 $salt = '';
137 $salt .= $chars[$this->random(0, 61)];
139 return $salt;
143 * Initialize the passed variable with a salt if needed.
145 * If $salt is not null, the value is kept, but the lenght restriction is
148 * @param string|null &$salt The salt, pass null if you want one generated
149 * @param int $len The length of the salt
150 * @param bool $cut Apply length restriction to existing salt?
152 public function init_salt(&$salt, $len = 32, $cut = true)
154 if (is_null($salt)) {
155 $salt = $this->gen_salt($len);
158 if (strlen($salt) > $len && $cut) $salt = substr($salt, 0, $len);
177 * @param string $salt The salt to use, null for random
180 public function hash_smd5($clear, $salt = null)
182 $this->init_salt($salt, 8);
184 if (defined('CRYPT_MD5') && CRYPT_MD5 && $salt !== '') {
185 return crypt($clear, '$1$' . $salt . '$');
188 return $this->hash_apr1($clear, $salt, '1');
200 * @param string $salt The salt to use, null for random
203 public function hash_lsmd5($clear, $salt = null)
205 $this->init_salt($salt, 8);
206 return "{SMD5}" . base64_encode(md5($clear . $salt, true) . $salt);
220 * @param string $salt The salt to use, null for random
224 public function hash_apr1($clear, $salt = null, $magic = 'apr1')
226 $this->init_salt($salt, 8);
229 $text = $clear . '$' . $magic . '$' . $salt;
230 $bin = pack("H32", md5($clear . $salt . $clear));
240 if ($i % 3) $new .= $salt;
258 return '$' . $magic . '$' . $salt . '$' . $tmp;
293 * @param string $salt The salt to use, null for random
296 public function hash_ssha($clear, $salt = null)
298 $this->init_salt($salt, 4);
299 return '{SSHA}' . base64_encode(pack("H*", sha1($clear . $salt)) . $salt);
308 * @param string $salt The salt to use, null for random
311 public function hash_crypt($clear, $salt = null)
313 $this->init_salt($salt, 2);
314 return crypt($clear, $salt);
362 * least 18 bytes. You can pass the crypted hash as salt.
365 * @param string $salt The salt to use, null for random
368 public function hash_kmd5($clear, $salt = null)
370 $this->init_salt($salt);
372 $key = substr($salt, 16, 2);
398 * @param string $salt The salt to use, null for random
404 protected function stretched_hash($algo, $clear, $salt = null, $magic = 'P', $compute = 8)
407 if (is_null($salt)) {
408 $this->init_salt($salt);
409 $salt = $itoa64[$compute] . $salt; // prefix iteration count
411 $iterc = $salt[0]; // pos 0 of salt is log2(iteration count)
420 $salt = substr($salt, 1, 8);
423 $hash = hash($algo, $salt . $clear, true);
448 return '$' . $magic . '$' . $iterc . $salt . $output;
463 * @param string $salt The salt to use, null for random
469 public function hash_pmd5($clear, $salt = null, $magic = 'P', $compute = 8)
471 return $this->stretched_hash('md5', $clear, $salt, $magic, $compute);
485 * @param string $salt The salt to use, null for random
491 public function hash_drupal_sha512($clear, $salt = null, $magic = 'S', $compute = 15)
493 return substr($this->stretched_hash('sha512', $clear, $salt, $magic, $compute), 0, 55);
500 * @param null|string $salt
507 public function hash_hmd5($clear, $salt = null, $magic = 'H', $compute = 8)
509 return $this->hash_pmd5($clear, $salt, $magic, $compute);
521 * @param string $salt The salt to use, null for random
524 public function hash_djangosha1($clear, $salt = null)
526 $this->init_salt($salt, 5);
527 return 'sha1$' . $salt . '$' . sha1($salt . $clear);
539 * @param string $salt The salt to use, null for random
542 public function hash_djangomd5($clear, $salt = null)
544 $this->init_salt($salt, 5);
545 return 'md5$' . $salt . '$' . md5($salt . $clear);
560 * @param string $salt The salt to use, null for random
565 public function hash_seafilepbkdf2($clear, $salt = null, $opts = [])
567 $this->init_salt($salt, 64);
586 $hash = hash_pbkdf2($algo, $clear, hex2bin($salt), $iter, 0);
587 return "PBKDF2$prefixalgo\$$iter\$$salt\$$hash";
597 * @param string $salt The salt to use, null for random
602 public function hash_djangopbkdf2($clear, $salt = null, $opts = [])
604 $this->init_salt($salt, 12);
622 $hash = base64_encode(hash_pbkdf2($algo, $clear, $salt, $iter, 0, true));
623 return "pbkdf2_$algo\$$iter\$$salt\$$hash";
630 * @param string $salt The salt to use, null for random
635 public function hash_djangopbkdf2_sha256($clear, $salt = null, $opts = [])
638 return $this->hash_djangopbkdf2($clear, $salt, $opts);
645 * @param string $salt The salt to use, null for random
650 public function hash_djangopbkdf2_sha1($clear, $salt = null, $opts = [])
653 return $this->hash_djangopbkdf2($clear, $salt, $opts);
663 * A full hash should be given as salt (starting with $a2$) or this
664 * will break. When no salt is given, the iteration count can be set
668 * @param string $salt The salt to use, null for random
673 public function hash_bcrypt($clear, $salt = null, $compute = 10)
679 if (is_null($salt)) {
681 $salt = '$2y$' . str_pad($compute, 2, '0', STR_PAD_LEFT) . '$' .
685 return crypt($clear, $salt);
699 * @param string $salt The salt to use, null for random
704 public function hash_sha2($clear, $salt = null, $opts = [])
722 $this->init_salt($salt, 8, false);
724 return crypt($clear, '$' . $prefix . '$' . $salt . '$');
726 return crypt($clear, '$' . $prefix . '$' . $rounds . '$' . $salt . '$');
731 public function hash_sha512($clear, $salt = null, $opts = [])
734 return $this->hash_sha2($clear, $salt, $opts);
738 public function hash_sha256($clear, $salt = null, $opts = [])
741 return $this->hash_sha2($clear, $salt, $opts);
753 * @param string $salt The salt to use, null for random
756 public function hash_mediawiki($clear, $salt = null)
758 $this->init_salt($salt, 8, false);
759 return ':B:' . $salt . ':' . md5($salt . '-' . md5($clear));