dos3018 2014-11-20 05:37
浏览 35

登录不适用于个人服务器

When I try to login an error of "Password is incorrect" is shown. But I know it's correct as it's on my server. Below is the registration form which interacts with the login mechanism on the server

Here is my code

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
      <td>
        <form name="form1" method="post" action=
        "%3C?php%20echo%20$_SERVER['PHP_SELF'];%20?%3E" id="form1">
          <table width="100%" border="0" cellpadding="3" cellspacing="1">
            <tr>
              <td colspan="3"><strong>Member Login</strong></td>
            </tr>

            <tr>
              <td width="78">Username</td>

              <td width="6">:</td>

              <td width="294"><input name="myusername" type="text" id=
              "myusername" /></td>
            </tr>

            <tr>
              <td>Password</td>

              <td>:</td>

              <td><input name="mypassword" type="password" id="mypassword" /></td>
            </tr>

            <tr>
              <td>&nbsp;</td>

              <td>&nbsp;</td>

              <td><input type="submit" name="Submit" value="Login" /></td>
            </tr>

            <tr>
              <td>&nbsp;</td>

              <td>&nbsp;</td>

              <td>
              <?php include( 'config.php'); // makes sure they filled it in if (isset($_POST[ 'Submit'])){ $username=$ _POST[ 'myusername']; $password=$ _POST[ 'mypassword']; $md5_pw=m d5($password); if($username==" " || $password=="" ) { echo( 'You did not fill in a required field.'); } else{ $query=m ysql_query( "SELECT *FROM admin
                                  WHERE user_name = '$username'  ")or die(mysql_error()); $query2=m ysql_num_rows($query); if ($query2==0 ) { echo( "That user does not exist in our database. <a     href=signup.php>Click Here to Register</a>"); } while($result=m ysql_fetch_array( $query )){ if($md5_pw !=$ result[ 'password']) { echo ( "incorrect password"); } else { session_start(); header( "Location: home.php"); } } } } ?></td>
            </tr>
          </table>
        </form>
      </td>
    </tr>
  </table>
</body>
</html>

Can you please help me identify the error(s)?

  • 写回答

1条回答 默认 最新

  • duansao6776 2014-11-20 06:23
    关注

    Since you always get Password is incorrect message even though the entered password is correct and the code that produces the message is the following

    if($md5_pw != $result['password'])
    {
        echo ("incorrect password");
    }
    

    It's obvious that the value of $md5_pw and $result['password'] are somehow different. You can check the values by adding echo 'md5: '.$md5_pw; and echo 'password in database: '.$result['password']; as follows

    echo 'md5: '.$md5_pw;
    echo 'password in database: '.$result['password'];
    
    if($md5_pw != $result['password'])
    {
        echo ("incorrect password");
    }
    

    Based on your comment, $result['password'] is always two characters short, so the solution is changing the length of password column in the database.

    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多