php salt每个用户的密码sha512-我这样做对吗


php salt my passwords per user sha512 - am I doing this right?

我正在尝试正确地为我的密码执行每个用户和整个站点的salt。这是我得到的:

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);

这是对的吗?感谢

人们经常使用唯一的salt与密码连接,然后使用hmac方法添加站点范围的哈希密钥:

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

$password = hash_hmac('sha512', $password . $salt, $sitewide_key);

这很好,只是从"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是足够安全的它自己

使用crypt,它在所有语言中都可用,其他程序也可以使用您的密码哈希:

$hash = crypt("secret", "$6$randomsalt$");

根据评论,我要做的是:将我的$combine更改为每个用户唯一但不存储在数据库中的内容。所以像:$combine = $pw . md5($pw) . 'PoniesAreMagical' . $site_salt . md5($pw);等…谢谢你的帮助。。。

所以,对于那些第一次想办法做到这一点的人(比如我)。。。这一切都与算法有关。。。使事物变得晦涩、独特、难以理解;因为如果有人想进入你的系统,他们必须弄清楚这一点。感谢大家的精彩评论。