-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
executable file
·137 lines (109 loc) · 4.38 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
//This script will handle login
session_start();
// check if the user is already logged in
if(isset($_SESSION['username']))
{
header("location: index.php");
exit;
}
require_once "partials/config.php";
$username = $password = $user_type = "";
$err = "";
// if request method is post
if ($_SERVER['REQUEST_METHOD'] == "POST"){
if(empty(trim($_POST['username'])) || empty(trim($_POST['password'])))
{
$err = "Please enter username and password";
echo "<script>alert('$err');</script>";
}
else{
$username = trim($_POST['username']);
$password = trim($_POST['password']);
}
if(empty($err))
{
$sql = "SELECT user_id,username,password FROM userdetail WHERE username = ?";
$stmt = mysqli_prepare($conn, $sql);
$param_username = $username;
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Try to execute this statement
if(mysqli_stmt_execute($stmt)){
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1)
{
mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password);
if(mysqli_stmt_fetch($stmt))
{
if(password_verify($password, $hashed_password))
{
// this means the password is corrct. Allow user to login
session_start();
$_SESSION["username"] = $username;
$_SESSION["id"] = $id;
$_SESSION["loggedin"] = true;
// $_SESSION["isSignedIn"] = true;
//Redirect user to welcome page
header("location: index.php");
}
else{
$err = "Username and password do not match.";
echo "<script>alert('$err');</script>";
}
}
}
else{
$err = "This user is not registered..";
echo "<script>alert('$err');</script>";
}
}
}
}
?>
<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">
<link rel="stylesheet" href="lstyle.css">
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<title>TechFindr-Login</title>
</head>
<body>
<div class="wrapper-right">
<div class="signup">
<p>Do not have an account?</p>
<button class="signup-btn" onclick="location.href='register.php'">Sign Up </button>
<div class="back">
<a href="index.php"><i class="fas fa-times"></i></a>
</div>
</div>
<div class="title">
<h1>Welcome Back,</h1>
<p>Sign In to your account</p>
</div>
<form action="" method="post">
<div class="form-card">
<span class="label">Username</span>
<div class="input-box">
<input type="text" id="username" name = "username" placeholder="Username">
<ion-icon name="person-outline"></ion-icon>
</div>
</div>
<div class="form-card">
<span class="label">Password</span>
<div class="input-box">
<input type="password" name="password" id="password" placeholder="Password">
<ion-icon name="lock-closed-outline"></ion-icon>
</div>
</div>
<input type="submit" value="Login" class="login-btn">
</form>
</div>
</body>
<script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.js"></script>
</html>