-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-indexconnect.php
57 lines (47 loc) · 1.56 KB
/
1-indexconnect.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
<?php
session_start();
// Database connection details
$servername = "localhost";
$username = "root"; // Use your database username
$password = ""; // Use your database password
$dbname = "mini_project";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$usn = $_POST['username'];
$pass = $_POST['password'];
// Prepare and bind
$stmt = $conn->prepare("SELECT password FROM uandp WHERE username = ?");
$stmt->bind_param("s", $usn);
// Execute the statement
$stmt->execute();
$result = $stmt->get_result();
// Check if any records were found
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$hashed_password = $row['password'];
// Verify the password
if (password_verify($pass, $hashed_password)) {
// Credentials are valid, redirect to dashboard
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $usn;
header("Location:2-dashboard.html");
exit();
} else {
// Invalid credentials, show error message
echo "Invalid username or password";
}
} else {
// No user found with that username, show error message
echo "Invalid username or password";
}
// Close statement
$stmt->close();
}
// Close connection
$conn->close();
?>