[英]PHP Session Login return wrong username and password
When trying to log in to my site, the script returns Im using a wrong username or password. 尝试登录到我的站点时,脚本使用错误的用户名或密码返回Im。
Head of index.html: index.html的标题:
<?php
session_start();
require_once 'classes/Membership.php';
$membership = new Membership();
if ($_POST && !empty ($_POST['username']) && !empty ($_POST['password'])) {
$response = $membership->validate_user($_POST['username'], $_POST['password']);
}
?>
Form in index.html: index.html中的表格:
<div class="login" id="register">
<form method="POST" action="" accept-charset="utf-8">
<fieldset>
<p>
<label for="username">Username</label><br />
<input type="text" name="username" value="" id="username">
</p>
<p>
<label for="password">Password</label><br />
<input type="password" name="password" value="" id="password">
</p>
</fieldset>
<input type="submit" class="button" value="Sign in">
</form>
</div>
<?php if(isset($response)) echo "<p class = 'error-msg'>" .$response.".</p>"; ?>
Membership.php 会员资格
<?php
require 'MySQL.php';
class Membership
{
function validate_user($username, $password)
{
$mysql = new MySQL();
$ensure_credentials = $mysql->verify_in_db($username,md5($password));
if ($ensure_credentials)
{
$_SESSION['status'] = 'authorized';
header("location: index_member.php");
}
else return "Please enter a correct username and password";
}
}
MySQL.php MySQL.php
<?php
require_once 'includes/constants.php';
class MySQL
{
private $conn;
function __construct()
{
$this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME)
or die ('There was a problem connecting to the database.');
}
function verify_in_db($username, $password)
{
$query = "SELECT *
FROM users
WHERE username = ? AND password = ?
LIMIT 1";
if ($stmt = $this->conn->prepare($query))
{
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
if ($stmt->fetch())
{
$stmt->close();
return true;
}
}
}
}
constants.php constants.php
<?php
// Define constants
define ('DB_SERVER', 'localhost');
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_NAME', 'membership');
There is no db password, dont be confused. 没有数据库密码,请不要混淆。 Standart DB on xampp.
xampp上的Standart DB。 The credentials I try to use are 100% correct, the sql constants too.
我尝试使用的凭据也是100%正确,sql常量也是如此。
maybe because of your password as you said. 可能是因为您所说的密码。 its
它的
'password'
but it should be something like this because of MD5 但是由于MD5,应该是这样的
'fglsdgjdfnfjlsmg905760657604657604jtvymwy'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.