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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看