doyrte8419 2018-07-02 12:13
浏览 19
已采纳

php - mysqli准备给我错误qhen开始登录

I create this code to check user login based in a form. But is giving me erros..Is not finding nothing... just say "INVALID USERNAME/PASSWORD Combination!"

    $uid = mysqli_real_escape_string($con, sanitize($_POST['email']));
$pwd = mysqli_real_escape_string($con, sanitize($_POST['password']));

if (empty($uid) || empty($pwd)) {

    header("Location: ../member?fail=1");
    exit();

} else {

    $stmt = $con->prepare("SELECT email, password FROM public_users WHERE email = ? AND password = ?");
    $stmt->bind_param('ss', $uid, $pwd);
    $stmt->execute();
    $stmt->bind_result($uid, $pwd);
    $stmt->store_result();

    if($stmt->num_rows == 1) {

        if($stmt->fetch()) {

           $secure_hash = password_verify($pwd, $stmt['password']);

           if($secure_hash == false) { 

              echo "Combination!";

           } else {

              echo "PASSWORD Combination!";
           }

        }

    } else {
        echo "INVALID USERNAME/PASSWORD Combination!";
    }        

}    

$stmt->close();

Please help this is for an text tomorrow at school :(

  • 写回答

1条回答 默认 最新

  • dpojoxa5613 2018-07-02 12:18
    关注

    You tried to get an email and a password from your database, but the password field already hashed.

    $stmt = $con->prepare("SELECT email, password FROM public_users WHERE email = ? AND password = ?");
    

    You should get a record only by email:

    $stmt = $con->prepare("SELECT email, password, age FROM public_users WHERE email = ? ");
    $stmt->bind_param('s', $uid);
    $stmt->execute();
    $stmt->bind_result($uid, $hashed_password, $age);
    $stmt->store_result();
    //.....
    

    and next verify password:

    $secure_hash = password_verify($pwd, $hashed_password);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line