密码MD5没看过怎么解决这个?

时间:2014-11-11 16:21:09

标签: php html

<?php
    error_reporting (E_ALL ^ E_NOTICE);
    session_start();
    ?>
    <html>
    <head>
    <title>Log in</title>
    </head>
    <body>
    <?php
    $form = "<form action='./log.php' method='POST'>
    <table>
    <tr>
        <td>Username</td>
        <td><input type='text' name='name'></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type='text' name='password'></td>
    </tr>
    <tr>
        <td></td>
        <td><input type='submit' name='loginbtn' value='Login'></td>
    </tr>
    </table>
    </form>";

        if ($_POST['loginbtn']) {
            $user = $_POST['name'];
            $password = $_POST['password'];
            if($user) {
                if($password) {
                    require('connect.php');
                    $password = md5($password)
                    //make user login info correct
                    $query = mysql_query("SELECT * FROM users where name= '$user'");
                    $numrows = mysql_num_rows($query);
                    if($numrows == 1) {
                        $row = mysql_fetch_assoc($query);
                        $dbid = $row['id'];
                        $dbuser = $row['name'];
                        $dbpass = $row['password'];
                        $dbactive = $row['active'];

                        if($password == $dbpass) {
                            if($dbactive == 1) {
                                //set session info
                                $_SESSION['id'] = $dbid;
                                $_SESSION['name'] = $dbuser;

                                echo "You have logged in as <b>$dbname</b> <a href='en/index.html'>Click Here</a> to go on next page";
                            }
                            else {
                                echo "You must activate your account to login. $form";
                            }

                        }
                        else {
                            echo "You did not enter the correct password";
                        }
                    }
                    else {
                        echo "The username you entered was not found. $form";
                    }

                    mysql_close();
                }
                else {
                    echo "Tou must eneter your password. $form";
                }
            }
            else {
             echo "Tou must eneter a username. $form";
            }
        }
        else {
            echo $form;
        }
    ?>
    </body>
    </html>

*我的注册系统以md5格式在db上输入密码。

但是此登录表单找不到我的密码并打印我的问题“您没有输入正确的密码”。

如何解决这个问题?*

坚持不懈地尝试解决问题

1 个答案:

答案 0 :(得分:0)

可以在将密码插入数据库时​​将一些空格或其他值与密码字段一起插入。所以再次检查您的插入代码。使用trim来制作密码md5,如$password = md5(trim($password))两侧(插入和选择)。还要注意它是区分大小写的。正如评论部分所说,不要使用md5,因为它不是那么安全。