use*_*600 1 php passwords password-protection
截至目前,我有这行代码
<?php
$pass = "12312312";
echo md5(crypt($pass))
?>
Run Code Online (Sandbox Code Playgroud)
我知道crypt可以随机生成salt但我不知道如何在用户输入上比较它.
我的登录表需要哪些字段?还有,我会在桌面上插入什么数据?
谢谢!
您可以将密码存储在表格中,如下所示
$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
Run Code Online (Sandbox Code Playgroud)
你可以检查密码
$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
}
Run Code Online (Sandbox Code Playgroud)