简体   繁体   English

哈希密码无法登录

[英]Hashed password wont login

Register.php Register.php

       $query = " 
        INSERT INTO users( 
            email,
            pass, 
            salt
        ) VALUES ( 
            :email, 
            :password, 
            :salt
        ) 
    "; 

      $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647)); 
    $password = hash('sha256', $_POST['password'] . $salt); 

    for($round = 0; $round < 65536; $round++) 
    { 
        $password = hash('sha256', $password . $salt); 
    } 

    $query_params = array( 
        ':email' => $_POST['email'],
        ':password' => $password, 
        ':salt' => $salt
    ); 

Login.php Login.php

        if($row) 
    { 

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

        if($check_password === $row['pass']) 
        { 
            // If they do, then we flip this to true 
            $login_ok = true; 
        } 
    } 

Passwords/usernames are correct so can't figure out why this isn't working. 密码/用户名是正确的,因此无法弄清楚为什么它不起作用。 In the database the hashed pass length is the same as the salt password which I am not sure is correct 在数据库中,哈希的通过长度与盐密码相同,我不确定该密码是否正确

Check if your pass column is varchar with length greater or equal of hashed password. 检查您的pass列是否为varchar,其长度大于或等于哈希密码。 I think your stored password has been truncated during saving. 我认为您存储的密码在保存期间已被截断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM