duansan9435 2014-06-13 13:47
浏览 44
已采纳

PHP登录代码错误与散列密码

Here is my Login code, it was working perfectly but after adding securities to password like hashing and coding it creates password exactly same to the saved password but even more longer. $hash is exactly same as password but then it continues to a very big digit. Please help to solve it. Thanks in advance.

$hash = hash('sha256',$check_password['Salt'].$hash1) this code has been used in registration form and though their is same formula in both page login and registration i dont understand why in login it takes such a linger number after it matches completely same to the one in DB that created while registration

<?php

//database connection

$username = $_POST['username'];
$password = $_POST['password'];

if(isset($_POST["submit"])) {

$check_table = "SELECT Email, Password, Salt FROM register where Email = '$username'";

$check_sql_query = mysql_query($check_table);

$check_num_rows = mysql_num_rows($check_sql_query);

$check_password = mysql_fetch_array($check_sql_query, MYSQL_ASSOC);
$hash1=hash('sha256',$password);


$hash = hash('sha256',$check_password['Salt'].$hash1);

if($hash != $check_password['Password']) {
    echo "Invalid Credentials";
    echo "<br />";
    echo $password;
    echo "<br />";
    echo $hash;
    echo "<br />";
    echo $check_password['Password'];
    echo "<br /><br /><br />";
    echo "salt value ".$check_password['Salt'];
}
else {
    echo "Welcome to Website";
}
}

?>

OUTPUT

Invalid Credentials
r12345678 => Password
fe55b0cf0832801955af05cb29015191f1299809d96df88a2484192423be3b7a => $hash
fe55b0cf0832801955af05cb290151 => Password


salt value 04cb1e96d31e9086ef9b36e1a9dbd6
  • 写回答

2条回答 默认 最新

  • duandai3964 2014-06-13 14:05
    关注

    Your password seems to be the first 30 characters of the hash... i think it may have something to do with the character limit of the varchar in your database.

    Can you also share the line which generates the password when the user is created before you store it in the table. Do you have a salted hash being applied the same way at both ends, when creating and when verifying

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探