-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthentification.php
79 lines (74 loc) · 2.15 KB
/
authentification.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html>
<head>
<meta charset="utf-8">
<title>Вход</title>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<div>
<div align="center"><h2>Вход</h2></div>
<form autocomplete="off" method="post" action="authentification.php" >
<center>
<div align="center">
<input type="text" required placeholder="Логин" name="Login"><br><br>
<input type="password" required placeholder="Пароль" name="Password"><br><br>
<div class="btn-group">
<input type="submit" name="send" value="Войти" />
<a href="register.php">Регистрация</a>
</div>
</div>
</center>
</form>
<?php
$flag='';
session_start();
if (isset($_SESSION['login'])) {
header('Location: Menu.php');
exit();
}
if (isset ($_POST['send'])){
include_once("connection_params.php");
$login = $_POST['Login'];
$password = $_POST['Password'];
// Проверяем есть ли такой логин в бд
if ($result = mysqli_query($connection, " SELECT login FROM users ")){
while($row = mysqli_fetch_assoc($result)){
if ($row['login'] == $login) {
$flag = 1;
}
}
}
if (!$flag){
echo "<tr><div>
<span><center>Пользователя с таким логином не существует</center></span></div>
</tr>";
}
else{
if ($result = mysqli_query($connection, " SELECT login, password, salt FROM users WHERE login='$login' ")){
$row = mysqli_fetch_assoc($result);
$salt = $row['salt'];
$password = md5($password.$salt);
if ($row['password'] == $password) {
#$_SESSION['login'] = $login;
header("Location: Menu.php");
exit();
}
else {
echo "<tr><div class='alert'>
<span><center>Неверный пароль</center></span></div>
</tr>";
}
}
}
}
if (isset($_GET['success'])) {
echo("<center>Вы успешно зарегистрированы. Теперь войдите</center>");
}
if (isset($_GET['logout'])) {
echo("<center>Вы успешно вышли</center>");
}
?>
</body>
</html>