doukong1901 2018-10-13 00:11
浏览 31
已采纳

以编程方式登录traccar php?

I had implement login traccar from this Link but why hashed not same and always return false ?

code:

$email = $this->param['email'];
    $password = $this->param['password'];
    $qselect ='SELECT u.id as uid, u.name as uname, u.hashedPassword as hashed,u.salt,u.admin 
                FROM users u INNER JOIN users us ON us.id = u.id WHERE us.email = "'.$email.'"'; 
    $row = $this->mysqli->query($qselect)->fetch_array();
    $key = $this->hexToStr(trim($row['salt']));
    $hashed = hash_pbkdf2("sha1",$password, $key,1000,24,true); 
    echo $this->strToHex($hashed)."---".$row['hashed']."-----".$row['salt'];
    var_dump(trim($this->strToHex($hashed))==trim($row['hashed']));
    exit();              
    if ($this->strToHex($hashed)==$row['hashed']){
        $_SESSION['loginstate'] = 1;
        echo 1;
    }else{
        echo 0;
    }

the result is D33DCA55ABD4CC5BC76F2BC0B4E63FE2C6F61F4C1EF2D47---D33DCA55ABD4CC5BC76F2BC0B4E603FE2C6F61F4C1EF2D47-----000000000000000000000000000000000000000000000000bool(false)

As you can see the only different is one number only when result hash from db is 63 and result hash from generate hash_pbkdf2 is 603, the different is zero, any problem can I fix?

  • 写回答

1条回答 默认 最新

  • doupaoshu8334 2018-10-13 05:45
    关注

    Solved by this code

    while($row = $q->fetch_array()){
            $data = $password;
            $key = hex2bin($row['salt']);
            $hashed = hash_pbkdf2('sha1',$data, $key,1000,24,true);
    
            echo bin2hex($hashed)."---".$row['hashed'];
            var_dump(strtoupper(bin2hex($hashed))==$row['hashed']);
    
            if (strtoupper(bin2hex($hashed))==$row['hashed']){
                            //session_start();
                            //$_SESSION['email'] = $email;
                        $_SESSION['hashedpassword'] = $password; 
                        header('location:page.php');
                          }
        }
    

    use bin2hex and hex2bin with hashed upper

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化