-
Notifications
You must be signed in to change notification settings - Fork 313
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (37 loc) · 1.19 KB
/
script.js
File metadata and controls
42 lines (37 loc) · 1.19 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
const usersTable = [
// Note: This is a fake table for educational purposes. Never store user credentials in plain text.
{ id: 1, username: "hello@world.com", password: "badpassword" },
{ id: 2, username: "test@user.com", password: "badpassword" },
{ id: 3, username: "email@domain.com", password: "badpassword" },
];
let renderSuccess = () => {
document.getElementById("success-message").hidden = false;
};
let renderError = () => {
document.getElementById("error-message").hidden = false;
};
let resetMessage = () => {
document.getElementById("success-message").hidden = true;
document.getElementById("error-message").hidden = true;
};
addEventListener("submit", (event) => {
event.preventDefault();
resetMessage();
let email = document.getElementById("email").value;
let password = document.getElementById("password").value;
console.log(`email submitted: ${email}`);
console.log(`password submitted: ${password}`);
let found = false;
for (user of usersTable) {
console.log(user.username);
if (user.username === email && user.password === password) {
found = true;
break;
}
}
if (found) {
renderSuccess();
} else {
renderError();
}
});