-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.php
More file actions
51 lines (47 loc) · 1.18 KB
/
authentication.php
File metadata and controls
51 lines (47 loc) · 1.18 KB
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
session_start();
include 'functions.php';
require_once 'lib/passwordLib.php';
if($_SERVER['REQUEST_METHOD'] != 'POST'){
header('Location: index.php');
exit;
}
if(isset($_POST['login'])){
$login = $_POST['login'];
if($login == ''){
unset($login);
}
}
if(isset($_POST['password'])){
$password = $_POST['password'];
if($password ==''){
unset($password);
}
}
if(empty($login) or empty($password)){
header('Location: index.php?login=empty_data');
exit;
}
reg_prepare($login);
reg_prepare($password);
$db = connect();
if($db->connect_errno) {
header('Location: index.php?login=db_error');
exit;
}
$query = "SELECT * FROM `USERS` WHERE (`Username` = '".$login."' OR `Email` = '".$login."')";
$res = $db->query($query);
if($res->num_rows > 0){
$row = $res->fetch_assoc();
if(password_verify($password, $row["Password"])){
$_SESSION['login'] = $row["Username"];
$_SESSION['id'] = $row["ID"];
$_SESSION['email'] = $row["Email"];
header('Location: index.php?login=ok');
exit;
}
header('Location: index.php?login=wrong_password');
exit;
}
header('Location: index.php?login=wrong_login_or_email');
?>