PHP 密码哈希


PHP Password Hashing

到目前为止,我有这行代码

<?php
    $pass = "12312312";
    echo md5(crypt($pass))
?>

我知道 crypt 可以随机生成盐,但我不知道如何在用户输入上比较它。

我的登录表需要哪些字段?另外,我将向表中插入哪些数据?

谢谢!

您可以将密码存储在表中,如下所示

$pass = "12312312";
// store this in table with separate column
$salt = md5("any variable"); // may be email or username
// generate password
$password = sha1($salt.$pass);
// now store salt and password in table

您可以像检查密码一样

$pass = "User input";
// get the user from database based on user id or username
// and test the password stored in db with
if($passwordFromTable == sha1($saltFromTable.$pass))
{
    // correct
}