-1
请我一直在尝试登录,但我似乎正在得到其他“未找到用户名和密码”。我不能使用此代码登录系统使用PDO
这里是我的代码登录:
<?php
session_start();
require 'lib/password.php';
if(isset ($_POST['submit'])){
$errMsg = '';
$username = trim($_POST['username']);
$password = trim($_POST['password']);
if($username == '')
$errMsg = 'You must enter your username<br>';
if ($password == '')
$errMsg = 'You must enter your password<br>';
if($errMsg == ''){
$records = $conn->prepare('SELECT id, username, password FROM users WHERE username = :username');
$records->bindParam(':username', $username);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
if(count($results) > 0 && password_verify($password, $results['password'])){
$_SESSION['username'] = $results['username'];
header('location:welcome.php');
exit;
}else{
$errMsg = 'Username and Password are not found<br>';
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
if(isset($errMsg)){
echo '<div style="color:#FF0000;text-align:left;font-size:12px;">'.$errMsg.'</div>';
}
?>
<form action="<?php echo $current_file; ?>" method="POST">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" name="submit" value="Log In">
<p>If you don't have an account, <a href="register.php">SIGNUP</a></p>
</form>
</body>
</html>
可能是什么问题。请有人帮忙吗?
您可以缩小哪些是失败的'count($ results)> 0'或'password_verify($ password,$ results ['password'])''?当你创建他们的账户时,你是否也修改了用户的用户名和密码? – chris85
确保密码列足够长以容纳散列。很多次,这是问题的根源。如果时间不够长,您需要更改列的长度,删除现有数据并重新开始。使用建议长度的varchar(255)。如果你的列是50,那么它会失败。 –
有点互动会很好。只是......一小时。浏览器选项卡是好事。 –