-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
30 lines (27 loc) · 998 Bytes
/
script.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
28
29
30
let users = [
{ username: 'user1', password: 'hashedPassword1' },
{ username: 'user2', password: 'hashedPassword2' },
// Add more users here
];
function hash(password, salt) {
// Implement the hashing function here
}
function validateUser(username, password) {
let user = users.find(user => user.username === username);
if (user) {
return hash(password, user.salt) === user.password;
} else {
return false;
}
}
document.getElementById('loginForm').addEventListener('submit', function(event) {
event.preventDefault();
let username = document.getElementById('username').value;
let password = document.getElementById('password').value;
if (validateUser(username, password)) {
// Redirect the user to the authenticated area of the website
window.location.href = 'dashboard.html';
} else {
document.getElementById('error').textContent = 'Invalid username or password.';
}
});