-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
54 lines (43 loc) · 1.42 KB
/
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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="login.css" />
</head>
</html>
<?php
/* User login process, checks if user exists and password is correct */
include 'db.php';
$sql = "SELECT * FROM users WHERE uid = :uid";
$usercheck = $pdo->prepare($sql);
$usercheck->bindParam(':uid', $_POST['uid']);
$usercheck->execute();
if ($usercheck->rowCount() == 0) {
// User doesn't exist
echo '<div class="alert">
<span class="closebtn" onclick="this.parentElement.style.display=\'none\';">×</span>
<strong>User doesn\'t exist!</strong> Enter the correct username or register for an account.
</div>';
}
else {
// User exists
$result = $usercheck->fetchAll();
//print_r($result[0]['first']);
$verify = password_verify($_POST['pwd'], $result[0]['pwd']);
if($verify) {
$_SESSION['email'] = $result[0]['email'];
$_SESSION['uid'] = $result[0]['uid'];
$_SESSION['first'] = $result[0]['first'];
$_SESSION['last'] = $result[0]['last'];
$_SESSION['active'] = $result[0]['active'];
// This is how we'll know the user is logged in
$_SESSION['logged_in'] = true;
header("location: profile.php");
}
else {
echo '<div class="alert">
<span class="closebtn" onclick="this.parentElement.style.display=\'none\';">×</span>
<strong>You have entered the wrong password, try again!</strong>
</div>';
}
}
?>