-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_login.php
57 lines (49 loc) · 1.45 KB
/
handle_login.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
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 'on');
require './DBC.php';
require './user.php';
require './log.php';
session_start();
if (empty($_SESSION["attempts"]))
{
$_SESSION["attempts"] = 0;
}
if (empty($_POST["username"]) || empty($_POST["password"]))
{
header("Location: home");
exit();
}
$user = new User();
$user->name = $_POST["username"];
$query = DBC::getConnection()->prepare("select username, password, language from User where username = ?");
$query->bind_param("s", $user->name);
$user->name = $_POST["username"];
$query->execute();
$query = $query->get_result();
if ($query->num_rows <= 0)
{
$_SESSION["attempts"] = $_SESSION["attempts"] + 1;
if ($_SESSION["attempts"] >= 3)
{
logToFile("Hack attempt detected! On nonexistent user: " . $_POST["username"] . ", attempts: " . $_SESSION["attempts"]);
}
die("Unknown user.<br><a href=\"home\">Back</a>");
}
$row = $query->fetch_assoc();
$user->name = $row["username"];
$user->password = $row["password"];
$user->language = $row["language"];
if (!password_verify($_POST["password"], $row["password"]))
{
$_SESSION["attempts"] = $_SESSION["attempts"] + 1;
if ($_SESSION["attempts"] >= 3)
{
logToFile("Hack attempt detected! On user: " . $_POST["username"] . ", attempts: " . $_SESSION["attempts"]);
}
die("Wrong password.<br><a href=\"home\">Back</a>");
}
$_SESSION["user"] = $user;
$_SESSION["attempts"] = 0;
header("Location: home");
?>