-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
71 lines (56 loc) · 1.75 KB
/
Copy pathindex.php
File metadata and controls
71 lines (56 loc) · 1.75 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
session_start();
require("database.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
<link rel="stylesheet" href="Styles/app.css">
</head>
<body>
<div class="form">
<form action="<?php $_SERVER['PHP_SELF'] ?>" onsubmit="return checklogin()" method="post">
<label for="user">User Name:</label>
<input type="text" name="user" id="user" autocomplete="off"><br>
<label for="pwd">Password:</label>
<input type="password" name="password" id="pwd"> <br>
<input type="submit" class="button" value="Login">
</form>
<p>Not Registered? <a href="signup.php">Sign Up</a></p>
</div>
<?php
if (isset($_GET["msg"])) {
$msg = $_GET["msg"];
echo "<p class='msg'>$msg</p>";
}
?>
<script src="Scripts/validation.js"></script>
</body>
</html>
<?php
if (!empty($_POST["user"]) && !empty($_POST["password"])) {
$username = filter_input(
INPUT_POST,
"user",
FILTER_SANITIZE_SPECIAL_CHARS
);
$password = $_POST["password"];
$query = "SELECT * FROM user_info WHERE username='$username'";
$data = mysqli_query($conn, $query);
$count = mysqli_num_rows($data);
if ($count > 0) {
$userdata = mysqli_fetch_assoc($data);
if ($userdata["username"] == $username && password_verify($password, $userdata["password"])) {
$_SESSION["username"] = $username;
header("location:main.php");
} else {
header("location:index.php?msg=Invalid Credentials");
}
} else {
header("location:index.php?msg=Not Registered");
}
}
?>