-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.php
51 lines (51 loc) · 1.6 KB
/
auth.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
<?php
require_once 'database.php';
if (isset($_COOKIE['cookie_token'])){
$token=$_COOKIE['cookie_token'];
$query="SELECT login FROM users WHERE token = '$token'";
$result=mysqli_query($link, $query);
$user=mysqli_fetch_row($result);
$user=$user[0];
$query="UPDATE players SET time = NULL WHERE login = '$user'";
$result=mysqli_query($link, $query);
$query="UPDATE users SET token = NULL WHERE login = '$user'";
$result=mysqli_query($link, $query);
mysqli_close($link);
setcookie('cookie_token', '');
setcookie('cookie_create_time', '');
setcookie('cookie_time', '');
header("Location: login.php");
die();
}
$login=$_POST['login'];
$password=$_POST['pswrd'];
$query="SELECT login FROM users";
$result=mysqli_query($link, $query);
for ($i=0; $i<mysqli_num_rows($result); ++$i){
$acc = mysqli_fetch_row($result);
if($login==$acc[0]){
goto exist;
}
}
mysqli_close($link);
header("Location: loginDOESNTEXIST.php");
die();
exist:
$query="SELECT password FROM users WHERE login = '$login'";
$result=mysqli_query($link, $query);
$acc_pass = mysqli_fetch_row($result);
$hash_password=$acc_pass[0];
if (password_verify ($password,$hash_password)){
$token=bin2hex(random_bytes(32));
$query = "UPDATE users SET token = '$token' WHERE login = '$login'";
$result = mysqli_query($link, $query);
setcookie('cookie_token', $token);
setcookie('cookie_create_time', time());
mysqli_close($link);
header("Location: index.php");
}
else {
mysqli_close($link);
header("Location: loginWRONGPASS.php");
}
?>