fear:login_js
This commit is contained in:
parent
eec9d78c1a
commit
4030decced
45
login.js
Normal file
45
login.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
document.getElementById("loginForm").addEventListener("submit", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const username = document.getElementById("username").value.trim();
|
||||||
|
const password = document.getElementById("password").value.trim();
|
||||||
|
const errorBox = document.getElementById("errorBox");
|
||||||
|
|
||||||
|
errorBox.style.display = "none";
|
||||||
|
errorBox.innerText = "";
|
||||||
|
|
||||||
|
if (!username || !password) {
|
||||||
|
showError("Username dan password harus diisi");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password.length < 6) {
|
||||||
|
showError("Password minimal 6 karakter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const usersData = localStorage.getItem("users");
|
||||||
|
const users = usersData ? JSON.parse(usersData) : [];
|
||||||
|
|
||||||
|
const user = users.find(u => u.username === username);
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
showError("Username tidak ditemukan");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.password !== password) {
|
||||||
|
showError("Password salah");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Login success
|
||||||
|
localStorage.setItem("loggedInUser", JSON.stringify(user));
|
||||||
|
window.location.href = "mainboard.html";
|
||||||
|
});
|
||||||
|
|
||||||
|
function showError(msg) {
|
||||||
|
const errorBox = document.getElementById("errorBox");
|
||||||
|
errorBox.innerText = msg;
|
||||||
|
errorBox.style.display = "block";
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user