dtncv04228 2016-08-22 20:31
浏览 9

简单===匹配失败的PHP

I am trying to match user input password with stored one in database. Until now it was working perfectly fine But all of sudden started behaving weird.

Script started showing error of Invalid Email id or password despite information is correct. Refreshing window Immediately after error displayed shows username stored in $_Session variable (which means user is logged in).

But how is this possible when user didn't reached to the point where username get stored in $_session.

Anyway, I tried to unset session variable at the beginning of script thinking there $_session is not destroyed completely (though it was) but that didn't worked too.

I have already tested using strcmp at $check_password===$row['password'] but no success. I also tested this with "==" operators but no luck.

Surprisingly, when i try this on localhost, it works fine but on server it produce error as mentioned.

I checked error log but nothing was there. any clue, what is causing this?

foreach($result as $row)
{
    $pass = hash('sha256', $_POST['password'] . $row['salt']);
    for($round = 0; $round < 65536; $round++) { $check_password = hash('sha256', $pass . $row['salt']); }

    if($check_password===$row['password'])
    {
        // check if e-mail verification has been done or not
        if(strcmp($row['activation'],"Active")==0)
        {               
            $_SESSION['username'] = $row['username'];

            $response['status'] = 'success';
            $response['message'] = 'Login successful.';
        }
        else
        {
            $response['status'] = 'failure';
            $response['message'] = 'Your Account is Not verified Yet. Kindly verify your account via Login panel Verify Account link.'; 
        }
    }
    else
    {
        $response['status'] = 'failure';
        $response['message'] = 'Invalid Email id or password.';  <--- Error point           
    }
}

Adding image of both same passwords. enter image description here

  • 写回答

1条回答 默认 最新

  • dongtan6206 2016-08-22 22:18
    关注

    I don't know if that was the right method to solve this issue but somehow this did the trick.

    adding following lines after $response['message'] = 'Login successful.'; solve the issue.

    echo json_encode($response);
    exit;
    

    But i am still not able to understand, how 'Invalid Email id or password.' error was displaying, when if statement was executed successfully up to login successful message.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值