doutu7123 2015-06-03 07:44
浏览 50

用于登录的php md5不会让我登录,并且一直说密码不正确

The md5 is posting to the database from the signup page so I know that's working, but everything I try here won't let me sign in and just keeps telling me I have the wrong password.

 <?php 
// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["user_name"]) ) {

        $user = mysql_real_escape_string($_POST["user_name"]);      
        $pass_word = mysql_real_escape_string(md5($_POST["pass_word"]));
   $pass_word=md5($pass_word);

    // Connect to the MySQL database  
    include "../connect_to_mysql.php"; 
    $sql = mysql_query("SELECT m_id FROM member WHERE user_name='$user' AND pass_word='$pass_word' LIMIT 1"); // query the person
     // ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
    $existCount = mysql_num_rows($sql); // count the row nums
    if ($existCount == 1) { // evaluate the count
         while($row = mysql_fetch_array($sql)){ 
             $id = $row["m_id"];
     }
         $_SESSION["m_id"] = $id;
         $_SESSION["user"] = $user;
         $_SESSION["pass_word"] = $pass_word;

         header("location: ../../index.php");
         exit();
    } else {
        echo 'That information is incorrect, try again <a     href="member_login.php">Click Here</a>'; 
        exit();
    }
}
?>
  • 写回答

2条回答 默认 最新

  • doue2666 2015-06-03 07:47
    关注

    You're running MD5 twice on your password.

    $pass_word = mysql_real_escape_string(md5($_POST["pass_word"]));
    $pass_word = md5($pass_word);
    

    Also, don't use MD5, it is completely unsafe, look into using bcrypt, it is secure, and very easy to implement in PHP. Replacing MD5 with this line of code will make your password hashes safe. Preferably add some salt, the salt being some random string. It will make breaking your passwords nigh impossible.

    $hash = password_hash($password . $salt, PASSWORD_BCRYPT);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)