首页 > 解决方案 > 一种避免在会话和数据库中存储纯文本密码的方法

问题描述

这是一个想法,我必须在会话和 SQL 中都不要存储纯文本密码(即使在帖子中需要)。你能告诉我你对这种方式的看法吗?

//The password entered by user in plain text
$password = $_POST['password'];

//Get data
$req = $db -> prepare('SELECT * FROM users WHERE uid = ?');
$req -> execute(array($_POST['uid']));
$data = $req -> fetch();

//Verifying password
if(password_verify($password, $data['hashed_password']))
{
     $_SESSION['rehash'] = password_hash($data['hashed_password'], PASSWORD_DEFAUT);
     $_SESSION['uid'] = $_POST['uid'];
}

//When checking credentials on other pages of the website:
if(password_verify($data['hashed_password'], $_SESSION['rehash'])
{
     //Private things here
}

我在同一类型的主题上看到了很多主题,即使我不这么认为,如果这是重复的,请随时关闭此主题。

标签: phpmysqlsecurityhashpasswords

解决方案


推荐阅读