Я пытаюсь создать систему входа в свой проект, но я не знаю, как проверить, правильно ли введен пароль.PHP- Login system
login.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once("guest.php");
require_once("db.php");
$error = "";
global $tf_handle;
$gb = new guest();
if(isset($_POST['login']))
{
$u_email = mysqli_real_escape_string($tf_handle, $_POST['email']);
$u_password = mysqli_real_escape_string($tf_handle, $_POST['password']);
$check = $gb->email_exist($tf_handle,$u_email); // check if email exist in database
if($check) // if true
{
//check if the password is right
$chpassword = mysqli_query($tf_handle,"SELECT * FROM `users` WHERE `email` = '$u_email' AND `password` = '$u_password'");
if($chpassword)
{
$error = "Thanks for loggin , you will be redirected...";
header("refresh:3;url=index.php");
}
else
{
$error = "Email Doesn't Exist";
}
}
else
{
$error = "Wrong information";
}
}
?>
<!doctype html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" href="css/styles.css" />
</head>
<body>
<div id="error" style="<?php if ($error !=""){?> display:block;<?php }?>"><?php echo $error;?></div>
<div id="wrapper">
<div id="menu">
<a href="Registration.php">Sign Up</a>
<a href="Login.php">Login</a>
</div>
<div id="formDiv">
<form method="POST" action="Login.php">
<label>Email:</label><br/>
<input type="text" name="email" class="inputFields" required /><br/><br/>
<label>Password:</label><br/>
<input type="password" name="password" class="inputFields" required /><br/><br/>
<input type="checkbox" name="keep" />
<label>Keep me logged in</label><br/><br/>
<input type="submit" name="login" class="theButtons" value="Login!" />
</form>
</div>
</div>
</body>
</html>
guest.php
<?php
require_once('db.php');
class guest
{
function email_exist($email,$con)
{
$result = mysqli_query($con,"SELECT * FROM `users` WHERE `email` = '$email'");
if(mysqli_num_rows($result) == 1)
{
return true;
}
else
{
return false;
}
}
}
Проблема заключается в строке ниже:
$chpassword = mysqli_query($tf_handle,"SELECT * FROM `users` WHERE `email` = '$u_email' AND `password` = '$u_password'");
или функции email_exist()
Это делает мой вход в систему, даже если пароль неверен.
Вы действительно должны использовать РНР [встроенные функции] (http://jayblanchard.net/proper_password_hashing_with_PHP.html) в защитите пароли. Если вы используете версию PHP менее 5.5, вы можете использовать 'password_hash()' [пакет совместимости] (https://github.com/ircmaxell/password_compat). –
[Ваш скрипт подвержен риску инъекций SQL.] (Http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Узнайте о [подготовленном] (http: //en.wikipedia.org/wiki/Prepared_statement) [утверждения] (http://php.net/manual/en/pdo.prepared-statements.php). –