我有表“用户”然后里面是列“用户名”和“密码”
用户名 = 管理员
密码(散列)= 管理员
<?php
$message = "";
if (isset($_POST['submit'])){
$username = trim(mysql_prep($_POST['user_name']));
$password = trim(mysql_prep($_POST['password']));
$hashed_password = sha1($password);
if (empty($username) || empty($password)){
$message = "You must enter username and password" . "<br />";
} else {
$query = "SELECT * ";
$query .= "FROM user ";
$query .= "WHERE user_name = '{$username}' ";
$query .= "AND password = '{$hashed_password}' ";
$query .= "LIMIT 1";
$result = mysql_query($query);
verify_database($result);
if (mysql_num_rows($result) == 1){
$found_user = mysql_fetch_array($result);
redirect_to("content.php");
} else {
$message = "Invalid username or password" . "<br />";
}
}
}
?>
<form action="login.php" method="post">
<?php echo $message; ?>
User Name: <input type="text" name="user_name"/><br />
Password: <input type="password" name="password"/><br />
<input type="submit" name="submit" value="Login"/>
</form>
现在的问题是即使我输入了正确的用户名和密码。我不断收到“无效的用户名或密码”。