-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.js
31 lines (27 loc) · 1.28 KB
/
login.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
31
document.addEventListener('DOMContentLoaded', () => {
const signInBtn = document.querySelector('.custom-button');
const usernameInput = document.querySelector('#username');
const passwordInput = document.querySelector('#password');
const errorMessage = document.querySelector('.error-message');
// Add event listener for the click event on the sign-in button
signInBtn.addEventListener('click', () => {
const username = usernameInput.value;
const password = passwordInput.value;
// Retrieve the registered user from local storage
const storedUser = JSON.parse(localStorage.getItem('user'));
// Check if the entered credentials match the stored user
if (storedUser && storedUser.username === username && storedUser.password === password) {
// Redirect to the dashboard page
window.location.href = 'dashboard.html';
} else {
// Show an error message if the credentials don't match
errorMessage.textContent = 'Invalid username or password';
}
});
// Add event listener for the keypress event on the password input field
passwordInput.addEventListener('keypress', (event) => {
if (event.key === 'Enter') {
signInBtn.click();
}
});
});