$query = "SELECT * FROM users WHERE username = '$username'";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) < 1)
{
header("Location: ../index.php?login=username");
exit();
}
else
{
if($row = mysqli_fetch_assoc($query_run))
{
//deshashing password
$hashedPwdCheck = password_verify($password, $row['password']);
if($hashedPwdCheck == false)
{
header("Location: ../index.php?login=false");
exit();
}
elseif($hashedPwdCheck == true)
{
//login the user here
$_SESSION ['u_name'] = $row['username'];
$_SESSION ['u_email'] = $row['email'];
$_SESSION ['u_password'] = $row['password'];
$_SESSION ['u_id'] = $row['userid'];
header("Location: ../index.php?login=success");
exit(); 以上是登录代码。
下面是存储密码并对其进行散列的注册代码。
else
{
//hashing password
$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
//insert the user into the database
$query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$hashedPwd');";
mysqli_query($con, $query);
header("Location: ../register.php?register=success");
exit();
}请帮帮忙,我有点搞不懂为什么这不管用。
你好,罗斯
发布于 2017-10-06 19:31:35
存储散列密码的列不够长。它应该超过60个字符,我建议使用VARCH(255)或TEXT来解释将来对password_hash()函数的任何更改,这可能会产生更长的哈希。
警告
您不应该将密码存储在会话数组中,因为它暴露了密码被劫持的可能性。
小波比说http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php了解了MySQLi的准备好了语句。
“没有sql_injection,因为我的变量上有一个函数,将输入的文本转换为纯文本.
mysqli_real_escape_string($con, $_POST['registerEmail']);”
甚至 http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string 都不安全!
https://stackoverflow.com/questions/46612606
复制相似问题