-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckcorrespondence.php
More file actions
62 lines (49 loc) · 1.67 KB
/
Copy pathcheckcorrespondence.php
File metadata and controls
62 lines (49 loc) · 1.67 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
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
// Database connection details
$dbServer = 'oceanus.cse.buffalo.edu:3306';
$dbUsername = 'ugoajaer';
$dbPassword = '50409878';
$dbName = 'cse442_2024_spring_team_aa_db';
// Create database connection
$conn = new mysqli($dbServer, $dbUsername, $dbPassword, $dbName);
// Check connection
if ($conn->connect_error) {
die(json_encode(['success' => false, 'message' => 'Connection failed: ' . $conn->connect_error]));
}
// Extract username and password from GET request
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
if (empty($username) || empty($password)) {
echo json_encode(['success' => false, 'message' => 'Username and password are required.']);
exit;
}
// Prepare SQL statement
$stmt = $conn->prepare("SELECT * FROM peace WHERE email = ?");
// Bind parameters
$stmt->bind_param("s", $username);
// Execute the statement
$stmt->execute();
// Get the result
$result = $stmt->get_result();
// Check if user exists
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
// Compare the plaintext password with the hashed password from the database
if (password_verify($password, $user['password'])) {
// Success
echo json_encode(['success' => true]);
} else {
// Invalid password
echo json_encode(['success' => false, 'message' => 'Invalid email or password.']);
}
} else {
// No user found
echo json_encode(['success' => false, 'message' => 'Invalid email or password...']);
}
// Close statement
$stmt->close();
// Close connection
$conn->close();
?>