crypt_gensalt
(PECL xpass >= 1.1.0)
crypt_gensalt — Compile a string for use as the salt argument to crypt
说明
Compile a string for use as the salt argument to crypt().
参数
prefix
-
Hashing method.
One of the
CRYPT_PREFIX_*
constant. Ifnull
, the best available hashing method will be selected. count
-
Controls the processing cost of the hash;
the valid range and exact meaning of count depend on the hashing method,
but larger numbers correspond to more costly hashes in
terms of CPU time and possibly memory usage.
If count is
0
, a low default cost will be selected.
返回值
Returns a string with the setting, or null
in case of an error.
示例
示例 #1 A crypt_gensalt() example
<?php
// Generate the salt
$salt = crypt_gensalt(CRYPT_PREFIX_BLOWFISH);
// Hash the password
$hash = crypt("secret", $salt);
// Check the hash
$test = hash_equals(crypt("secret", $hash), $hash);
var_dump($salt, $hash, $test);
?>
以上示例会输出:
string(29) "$2y$05$GcPykP.Am8C1.dGamdpwW." string(60) "$2y$05$GcPykP.Am8C1.dGamdpwW.1RR.7uicWvJPZfJfCEizZHqVWwuaJLm" bool(true)
参见
- crypt_preferred_method() - Get the prefix of the preferred hash method
- crypt() - 单向字符串散列
- hash_equals() - 可防止时序攻击的字符串比较
+添加备注
用户贡献的备注
此页面尚无用户贡献的备注。
备份地址:http://www.lvesu.com/blog/php/function.crypt-gensalt.php