在线的所有示例都显示了如下所示的crypt的使用:
$pass = crypt('something','$6$rounds=5000$anexamplestringforsalt$');
但是每个人都说你不应该定义轮次或盐.
那我该怎么用呢?
另外我遇到了一个问题:当我运行上面的代码时,它只运行50轮而不是5000轮,就像系统停止它一样.
任何帮助将不胜感激.
// – 解决方案 – //
我发现其中一些有用:
用于生成盐:
$salt = substr(str_shuffle("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
要么
如果你有一个linux服务器,这是一种更随机的生成盐的方法
$fp = fopen('/dev/urandom', 'r');
$randomString = fread($fp, 32);
fclose($fp);
Base 64编码以确保某些字符不会导致crypt出现问题
$salt = base64_encode($randomString);
对于哈希:
$hashed = crypt($passwordInput, '$6$'.$salt);
确认:
if (crypt($passwordInput, $hashed) == $hashed) {
// Valid action
} else {
// Invalid action
}
**特别感谢@lathspell帮助我们解决上述问题**