[英]Login does not work on personal server
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> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login" /></td>
</tr>
<tr>
<td> </td>
<td> </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)? 您能帮我找出错误吗?
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 由于即使输入的密码正确并且生成该消息的代码也始终如下,所以您始终会收到“ Password is incorrect
消息
if($md5_pw != $result['password'])
{
echo ("incorrect password");
}
It's obvious that the value of $md5_pw
and $result['password']
are somehow different. 显然$md5_pw
和$result['password']
的值有所不同。 You can check the values by adding echo 'md5: '.$md5_pw;
您可以通过添加echo 'md5: '.$md5_pw;
来检查值echo 'md5: '.$md5_pw;
and echo 'password in database: '.$result['password'];
并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. 根据您的评论, $result['password']
总是短两个字符,因此解决方案是更改数据库中password
列的长度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.