除了正确之外,我的密码不正确 [英] Getting my password incorrect besides being correct

查看:103
本文介绍了除了正确之外,我的密码不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚为什么我的密码不正确,我的注册页面正常工作。每次尝试登录时,都会显示login =密码错误。我尝试在网上找到所有可能的问题但没有任何帮助。

 <?php 
session_start();

if(isset($ _ POST ['submit'])){

include_once'dbt.inc.php';

$ username = mysqli_real_escape_string($ conn,$ _POST ['username']);
$ password = mysqli_real_escape_string($ conn,$ _POST ['password']);

//错误处理程序
if(empty($ username)|| empty($ password)){
header(Location:../main_login.php?login=空);
exit();
}
else {
$ sql =SELECT * FROM users WHERE user_username ='$ username';
$ run = mysqli_query($ conn,$ sql);
$ result = mysqli_num_rows($ run);

if($ result< 1){
header(Location:../main_login.php?login=error);
exit();
}
else {
if($ row = mysqli_fetch_assoc($ run)){
$ hashedpasswordcheck = password_verify($ password,$ row ['user_password']);
if($ hashedpasswordcheck == false){
header(Location:../main_login.php?login=incorrect password);
exit();
}
elseif($ hashedpasswordcheck == true){
//登录用户
$ _SESSION ['user_id'] = $ row ['user_id'];
$ _SESSION ['user_first'] = $ row ['user_first'];
$ _SESSION ['user_last'] = $ row ['user_last'];
$ _SESSION ['user_email'] = $ row ['user_email'];
$ _SESSION ['user_username'] = $ row ['user_username'];
$ _SESSION ['user_password'] = $ row ['user_password'];
header(Location:../main_login.php?login=success);
exit();






其他$ {
header(位置:.. /main_login.php?login=error);
exit();
}



?>


解决方案

如果您从password_verify获得不正确的错误回复,并且您知道它应该是正确的,确保你将散列变量放在单引号(')中而不是双引号()。

在PHP中任何以$在双引号内作为变量。


I can't figure out why I'm getting out my password incorrect, my signup page is working properly.Everytime I try to login it shows login=incorrect password in my url.I tried to figure ot every possible issue online but nothing helped me.

    <?php 
    session_start();

      if(isset($_POST['submit'])){

    include_once 'dbt.inc.php';

    $username = mysqli_real_escape_string($conn, $_POST['username']);
    $password = mysqli_real_escape_string($conn, $_POST['password']);

    //error handlers
    if(empty($username) || empty($password)){
        header("Location: ../main_login.php?login=empty");
        exit();
    }
    else{
        $sql = "SELECT * FROM users WHERE user_username = '$username'";
        $run = mysqli_query($conn, $sql);
        $result = mysqli_num_rows($run);

        if ($result < 1) {
            header("Location: ../main_login.php?login=error");
            exit(); 
        }
        else{
            if ($row = mysqli_fetch_assoc($run)) {
                $hashedpasswordcheck = password_verify($password, $row['user_password']);
                if ($hashedpasswordcheck == false) {
                    header("Location: ../main_login.php?login=incorrect password");
                    exit();
                }
                elseif($hashedpasswordcheck == true){
                    //log in user
                    $_SESSION['user_id'] = $row['user_id'];
                    $_SESSION['user_first'] = $row['user_first'];
                    $_SESSION['user_last'] = $row['user_last'];
                    $_SESSION['user_email'] = $row['user_email'];
                    $_SESSION['user_username'] = $row['user_username'];
                    $_SESSION['user_password'] = $row['user_password'];
                    header("Location: ../main_login.php?login=success");
                    exit();

                }
            }
        }

    }
}
           else{
          header("Location: ../main_login.php?login=error");
         exit();
}



 ?>

解决方案

If you get incorrect false responses from password_verify and you know it should be correct, make sure you are enclosing the hash variable in single quotes (') and not double quotes (").

In PHP anything that starts with a $ inside double quotes as a variable.

这篇关于除了正确之外,我的密码不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆