我正在尝试使用盐类加密来注册和登录表单,但我对它并不熟悉。所以一切都正常,除了登录不能识别密码,所以我很确定这是加密问题。这些是登记行:
$hash = hash('sha256', $password1);
function createSalt()
{
$text = md5(uniqid(rand(), true));
return substr($text, 0, 3);
}
$salt = createSalt();
$password = hash('sha256', $salt . $hash);这些是供登录的:
$userData = mysql_fetch_array($result, MYSQL_ASSOC);
$hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
if($hash != $userData['password'])
{
echo "Incorrect password";
}有人能指出这个问题吗。谢谢!
发布于 2014-02-24 20:35:51
实际上,您的代码应该在我所能看到的范围内工作,尽管它非常不安全!
也许您的数据库字段小于64个字符,或者您正在比较不同的密码。在任何情况下,都有一种更简单、更安全的密码散列方法,只需使用新函数散列()和核实()即可。对于早期的PHP版本,也存在一个兼容性包。
// Hash a new password for storing in the database.
// The function automatically generates a cryptographically safe salt.
$hashToStoreInDb = password_hash($password, PASSWORD_BCRYPT);
// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = password_verify($password, $existingHashFromDb);https://stackoverflow.com/questions/21996192
复制相似问题