-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
47 lines (39 loc) · 1.43 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
<?php
// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Database connection parameters
$db_host = "localhost";
$db_user = "root";
$db_password = "";
$db_name = "final_db";
// Create a database connection
$conn = new mysqli($db_host, $db_user, $db_password, $db_name);
// Check if the connection was successful
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get user_id and password from the submitted form
$user_id = $_POST["user_id"];
$password = $_POST["password"];
// Query to fetch user information based on user_id
$sql = "SELECT * FROM Users WHERE user_id = '$user_id'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
$hashed_password = $row["password"];
// Verify the provided password against the hashed password in the database
if (password_verify($password, $hashed_password)) {
// Password is correct, user is authenticated
echo "Login successful. Welcome, " . $row["first_name"] . " " . $row["last_name"];
} else {
// Incorrect password
echo "Incorrect password. Please try again.";
}
} else {
// User not found
echo "User not found. Please check your user_id.";
}
// Close the database connection
$conn->close();
}
?>