在注册期间,我使用 SHA 512 哈希和加盐密码
如下
// Create a random salt
$salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Create salted password (Careful not to over season)
$pass = hash('sha512', $pass.$salt);
salt 和 pass 存储在数据库中。但我不知道如何使用散列和加盐密码创建登录表单。谁能帮我下面是我的登录表格
//session_start();
if (
isset($_POST['username']) &&
isset($_POST['pass']) &&
!empty($_POST['username']) &&
!empty($_POST['pass'])
) {
$db = new PDO(
'mysql:host=localhost;dbname=timeline', // dsn
'root', // username
'' // password
);
$statement = $db->prepare('
SELECT * FROM users
WHERE username = ?
AND password = ?
');
$statement->execute(array(
$_POST['username'],
$_POST['pass']
));
if ($row = $statement->fetch()) {
$_SESSION['sess_user'] = $row['uid'];
$_SESSION['sess_name'] = $row['username'];
include('success.php');
} else include('fail.php');
} else include('fail.php');