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 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败