-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcredentials.html
More file actions
51 lines (45 loc) · 1.79 KB
/
credentials.html
File metadata and controls
51 lines (45 loc) · 1.79 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<script src="login.js" defer></script>
</head>
<body>
<h1>Login to Address Book</h1>
<form id="loginForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br>
<button type="submit">Login</button>
<p id="message"></p>
</form>
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('loginForm');
const message = document.getElementById('message');
form.addEventListener('submit', async function(event) {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// Fetch credentials from JSON file
const response = await fetch('credentials.json');
const credentials = await response.json();
// Check if credentials match
const user = credentials.find(c => c.username === username && c.password === password);
if (user) {
message.textContent = 'Login successful!';
message.style.color = 'green';
// Redirect to another page or perform other actions
window.location.href = 'dashboard.html'; // Example redirect
} else {
message.textContent = 'Invalid username or password.';
message.style.color = 'red';
}
});
});
</body>
</html>