-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreg.js
27 lines (23 loc) · 968 Bytes
/
reg.js
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
// Login Function
function saveLoginDetails(event) {
event.preventDefault();
// Get values from the login form
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
// Check if the user is registered
fetch('users.txt')
.then(response => response.text())
.then(data => {
const users = JSON.parse(data);
const user = users.find(user => user.username === username && user.password === password);
if (user) {
// Save login details to localStorage
localStorage.setItem("username", username);
localStorage.setItem("password", password);
// Redirect to the quiz page
window.location.href = "quiz.html";
} else {
alert("Incorrect username or password. Please try again.");
}
});
}