-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
83 lines (82 loc) · 3.16 KB
/
index.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
80
81
82
83
<?php
include './config.php';
session_unset();
$loginError = 'noshow';
if($_SERVER['REQUEST_METHOD'] == "POST"){
$username = $_POST['username'];
$password = $_POST['password'];
if($dbConection -> connect_error){
die("Connection error");
}
else{
$selectCmd = "SELECT * FROM user_tb WHERE username='$username';";
$result = $dbConection->query($selectCmd);
if($result-> num_rows > 0){
$user = $result -> fetch_assoc();
$hashedPass = $user['password'];
if(password_verify($password,$hashedPass)){
if($user['title'] == 'admin'){
$_SESSION['username'] = $username;
header("location:panelAdmin/");
}
else{
$_SESSION['username'] = $username;
header("location:panelUser/");
}
}
else{
$loginError = 'show';
}
}
else{
$loginError = 'show';
}
$dbConection -> close();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shelfish Readers Library</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link rel="stylesheet" href="./css/style.css">
</head>
<body class="loginPage">
<header>
<h1>Shelfish Readers Library</h1>
</header>
<main class="login">
<form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
<fieldset class="border border-2">
<div class="info">
<div>
<label class='form-label'>Username: </label>
<input type="text" class='form-control' name="username" placeholder="Type your username" required/>
</div>
<div>
<label class='form-label'>Password: </label>
<input type="password" class='form-control' name="password" placeholder="Type your password" required/>
</div>
</div>
<p class="error <?php echo $loginError ?>">*username/password invalid</p>
<!-- <div class="checkbox">
<input type="checkbox" />
<label>Remember Me</label>
</div> -->
<button type="submit" class="btn btn-secondary">Log in</button>
<div class="reg">
<p>Not a member?</p>
<a href="./register.php" class="link-dark">Register</a>
</div>
</fieldset>
</form>
</main>
<footer>
<span>Copyright © 2022 AMS Company | Design by Alyce, Marcelo, Samridh</span>
</footer>
</body>
</html>