10

我正在尝试为我的密码正确地执行每个用户和站点范围的盐。这是我所拥有的:

require('../../salt.php'); //this is above the web root and provides $salt variable
$pw = mysql_real_escape_string($_POST['pw']);
$per_user_salt = uniqid(mt_rand());
$site_salt = $salt //from salt.php that was required on first line
$combine = $pw . $per_user_salt . $site_salt;
$pw_to_put_in_db = hash("sha512", $combine);

这是正确的吗?谢谢

4

4 回答 4

0

人们通常使用与密码连接的唯一盐,然后使用 hmac 方法添加站点范围的散列密钥:

http://www.php.net/manual/en/function.hash-hmac.php

$password = hash_hmac('sha512', $password . $salt, $sitewide_key);
于 2011-06-25T18:17:35.610 回答
0

这很好,只是从“sha512”中删除了 ” :)

$pw = $_POST['pw'];
$per_user_salt = uniqid(mt_rand());
$site_salt = $salt //from salt.php that was required on first line
$combine = $pw . $per_user_salt . $site_salt;
$pw_to_put_in_db = hash(sha512, $combine);

不必使用 md5 sha512 本身就足够安全

于 2013-06-08T10:56:50.447 回答
0

使用 crypt,它适用于所有语言,您的密码哈希值也可用于其他程序:

$hash = crypt("secret", "$6$randomsalt$");
于 2013-06-13T18:12:34.087 回答
-2

根据这里的评论,我要做的是:将 my 更改$combine为每个用户唯一但不存储在 db 中的东西。像这样的东西:$combine = $pw . md5($pw) . 'PoniesAreMagical' . $site_salt . md5($pw);等等等等等等...感谢您的帮助...

所以 - 对于那些第一次尝试弄清楚如何做到这一点的人(像我一样)......这一切都与算法有关......让一些模糊,独特,难以理解的东西; 因为如果有人想进入你的系统,他们将不得不弄清楚这一点。感谢所有人的精彩评论。

于 2011-07-01T05:13:22.197 回答