建议使用password_hash
存储密码.不要将它们分离为数据库和文件.
假设我们有以下输入:
$password = $_POST['password'];
首先通过以下操作对密码进行哈希:
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
然后查看输出:
var_dump($hashed_password);
如你所见,它是散列的.(我假设您已经完成了这些步骤).
现在,您将这个哈希密码存储在数据库ensuring your password column is large enough to hold the hashed value (at least 60 characters or longer)中.当用户要求登录时,您可以通过以下操作在数据库中使用此哈希值判断密码输入:
// Query the database for username and password
// ...
if(password_verify($password, $hashed_password)) {
// If the password inputs matched the hashed password in the database
// Do something, you know... log them in.
}
// Else, Redirect them back to the login page.
Official Reference