-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
37 lines (31 loc) · 1.13 KB
/
script.js
File metadata and controls
37 lines (31 loc) · 1.13 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
let accounts = {};
function showCreateAccount() {
document.getElementById('login-form').style.display = 'none';
document.getElementById('create-account-form').style.display = 'block';
}
function showLogin() {
document.getElementById('login-form').style.display = 'block';
document.getElementById('create-account-form').style.display = 'none';
}
function createAccount() {
const name = document.getElementById('create-name').value;
const username = document.getElementById('create-username').value;
const password = document.getElementById('create-password').value;
if (accounts[username]) {
alert('Username already exists!');
} else {
accounts[username] = { name, password };
alert('Account created successfully!');
showLogin();
}
}
function login() {
const username = document.getElementById('login-username').value;
const password = document.getElementById('login-password').value;
if (accounts[username] && accounts[username].password === password) {
sessionStorage.setItem('loggedIn', username);
window.location.href = 'dashboard.html';
} else {
alert('Invalid username or password!');
}
}