Lines Matching defs: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($hash, 7);
88 $salt = substr(base64_decode(substr($hash, 6)), 20);
91 $salt = substr(base64_decode(substr($hash, 6)), 16);
94 $salt = $m[1];
97 $salt = $m[3];
114 $salt = $hash;
117 $salt = substr($hash, 0, 2);
122 $newhash = $this->$call($clear, $salt, $magic);
130 * Create a random salt
132 * @param int $len The length of the salt
137 $salt = '';
140 $salt .= $chars[$this->random(0, 61)];
142 return $salt;
146 * Initialize the passed variable with a salt if needed.
148 * If $salt is not null, the value is kept, but the lenght restriction is
151 * @param string|null &$salt The salt, pass null if you want one generated
152 * @param int $len The length of the salt
153 * @param bool $cut Apply length restriction to existing salt?
155 public function init_salt(&$salt, $len = 32, $cut = true)
157 if (is_null($salt)) {
158 $salt = $this->gen_salt($len);
161 if (strlen($salt) > $len && $cut) $salt = substr($salt, 0, $len);
180 * @param string $salt The salt to use, null for random
183 public function hash_smd5($clear, $salt = null)
185 $this->init_salt($salt, 8);
187 if (defined('CRYPT_MD5') && CRYPT_MD5 && $salt !== '') {
188 return crypt($clear, '$1$' . $salt . '$');
191 return $this->hash_apr1($clear, $salt, '1');
203 * @param string $salt The salt to use, null for random
206 public function hash_lsmd5($clear, $salt = null)
208 $this->init_salt($salt, 8);
209 return "{SMD5}" . base64_encode(md5($clear . $salt, true) . $salt);
223 * @param string $salt The salt to use, null for random
227 public function hash_apr1($clear, $salt = null, $magic = 'apr1')
229 $this->init_salt($salt, 8);
232 $text = $clear . '$' . $magic . '$' . $salt;
233 $bin = pack("H32", md5($clear . $salt . $clear));
243 if ($i % 3) $new .= $salt;
261 return '$' . $magic . '$' . $salt . '$' . $tmp;
296 * @param string $salt The salt to use, null for random
299 public function hash_ssha($clear, $salt = null)
301 $this->init_salt($salt, 4);
302 return '{SSHA}' . base64_encode(pack("H*", sha1($clear . $salt)) . $salt);
311 * @param string $salt The salt to use, null for random
314 public function hash_crypt($clear, $salt = null)
316 $this->init_salt($salt, 2);
317 return crypt($clear, $salt);
365 * least 18 bytes. You can pass the crypted hash as salt.
368 * @param string $salt The salt to use, null for random
371 public function hash_kmd5($clear, $salt = null)
373 $this->init_salt($salt);
375 $key = substr($salt, 16, 2);
401 * @param string $salt The salt to use, null for random
407 protected function stretched_hash($algo, $clear, $salt = null, $magic = 'P', $compute = 8)
410 if (is_null($salt)) {
411 $this->init_salt($salt);
412 $salt = $itoa64[$compute] . $salt; // prefix iteration count
414 $iterc = $salt[0]; // pos 0 of salt is log2(iteration count)
423 $salt = substr($salt, 1, 8);
426 $hash = hash($algo, $salt . $clear, true);
451 return '$' . $magic . '$' . $iterc . $salt . $output;
466 * @param string $salt The salt to use, null for random
472 public function hash_pmd5($clear, $salt = null, $magic = 'P', $compute = 8)
474 return $this->stretched_hash('md5', $clear, $salt, $magic, $compute);
488 * @param string $salt The salt to use, null for random
494 public function hash_drupal_sha512($clear, $salt = null, $magic = 'S', $compute = 15)
496 return substr($this->stretched_hash('sha512', $clear, $salt, $magic, $compute), 0, 55);
503 * @param null|string $salt
510 public function hash_hmd5($clear, $salt = null, $magic = 'H', $compute = 8)
512 return $this->hash_pmd5($clear, $salt, $magic, $compute);
524 * @param string $salt The salt to use, null for random
527 public function hash_djangosha1($clear, $salt = null)
529 $this->init_salt($salt, 5);
530 return 'sha1$' . $salt . '$' . sha1($salt . $clear);
542 * @param string $salt The salt to use, null for random
545 public function hash_djangomd5($clear, $salt = null)
547 $this->init_salt($salt, 5);
548 return 'md5$' . $salt . '$' . md5($salt . $clear);
563 * @param string $salt The salt to use, null for random
568 public function hash_seafilepbkdf2($clear, $salt = null, $opts = [])
570 $this->init_salt($salt, 64);
589 $hash = hash_pbkdf2($algo, $clear, hex2bin($salt), $iter, 0);
590 return "PBKDF2$prefixalgo\$$iter\$$salt\$$hash";
600 * @param string $salt The salt to use, null for random
605 public function hash_djangopbkdf2($clear, $salt = null, $opts = [])
607 $this->init_salt($salt, 12);
625 $hash = base64_encode(hash_pbkdf2($algo, $clear, $salt, $iter, 0, true));
626 return "pbkdf2_$algo\$$iter\$$salt\$$hash";
633 * @param string $salt The salt to use, null for random
638 public function hash_djangopbkdf2_sha256($clear, $salt = null, $opts = [])
641 return $this->hash_djangopbkdf2($clear, $salt, $opts);
648 * @param string $salt The salt to use, null for random
653 public function hash_djangopbkdf2_sha1($clear, $salt = null, $opts = [])
656 return $this->hash_djangopbkdf2($clear, $salt, $opts);
666 * A full hash should be given as salt (starting with $a2$) or this
667 * will break. When no salt is given, the iteration count can be set
671 * @param string $salt The salt to use, null for random
676 public function hash_bcrypt($clear, $salt = null, $compute = 10)
682 if (is_null($salt)) {
684 $salt = '$2y$' . str_pad($compute, 2, '0', STR_PAD_LEFT) . '$' .
688 return crypt($clear, $salt);
697 * @param $salt
701 public function hash_woltlab($clear, $salt = null)
703 return 'Bcrypt:' . $this->hash_bcrypt($clear, $salt);
717 * @param string $salt The salt to use, null for random
722 public function hash_sha2($clear, $salt = null, $opts = [])
740 $this->init_salt($salt, 8, false);
742 return crypt($clear, '$' . $prefix . '$' . $salt . '$');
744 return crypt($clear, '$' . $prefix . '$' . $rounds . '$' . $salt . '$');
749 public function hash_sha512($clear, $salt = null, $opts = [])
752 return $this->hash_sha2($clear, $salt, $opts);
756 public function hash_sha256($clear, $salt = null, $opts = [])
759 return $this->hash_sha2($clear, $salt, $opts);
771 * @param string $salt The salt to use, null for random
774 public function hash_mediawiki($clear, $salt = null)
776 $this->init_salt($salt, 8, false);
777 return ':B:' . $salt . ':' . md5($salt . '-' . md5($clear));