-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadministrator_verification.php
39 lines (31 loc) · 1.05 KB
/
administrator_verification.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
<?php
include 'connection.php';
$user_id = isset($_POST['user_id']) ? $_POST['user_id'] : '11728';
$password = isset($_POST['password']) ? $_POST['password'] : 'sumenth';
$department=isset($_POST['department'])? $_POST['department'] : 'IT';
// Secure the SQL query using prepared statement
$sql = "SELECT * FROM administrator WHERE user_id = ?;";
$stmt = mysqli_prepare($connect, $sql);
if (!$stmt) {
die("Error in prepared statement: " . mysqli_error($connect));
}
mysqli_stmt_bind_param($stmt, 's', $user_id);
mysqli_stmt_execute($stmt);
$res = mysqli_stmt_get_result($stmt);
if (!$res) {
die("Error in getting result: " . mysqli_error($connect));
}
if (mysqli_num_rows($res) > 0) {
$row = mysqli_fetch_assoc($res);
// Verify the password using password_verify() (assuming passwords are stored hashed)
if (($password=== $row['password'] ) && ($department=== $row['department'] ) ) {
echo "success";
} else {
echo "error";
}
} else {
echo "Username does not exist!";
}
mysqli_stmt_close($stmt);
mysqli_close($connect);
?>