Login vários usuário
by thvinic
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login Form with LocalStorage</title>
</head>
<body>
<form id="loginForm">
<label for="username">Usuário:</label>
<input type="text" id="username" name="username"><br>
<label for="password">Senha:</label>
<input type="password" id="password" name="password"><br>
<button type="submit">Ativar meu Aplicativo</button>
</form>
</body>
</html>
JavaScript
const users = [
{ username: "thiago", password: "1q2w3e4r", url: "https://brasilxapp.blogspot.com/p/recibo1.html" },
{ username: "murilo", password: "@comercial", url: "https://brasilxapp.blogspot.com/p/recibo1.html" },
{ username: "paulo", password: "123compressores", url: "https://brasilxapp.blogspot.com/p/recibo1.html" },
{ username: "elder", password: "autoparts", url: "https://brasilxapp.blogspot.com/p/recibo1.html" }
];
const loginForm = document.getElementById("loginForm");
loginForm.addEventListener("submit", (event) => {
event.preventDefault();
const username = document.getElementById("username").value;
const password = document.getElementById("password").value;
// Check if username and password are valid
const user = users.find(u => u.username === username && u.password === password);
if (user) {
// Store user data in localStorage
localStorage.setItem("currentUser", JSON.stringify(user));
// Redirect to user's URL
window.location.href = user.url;
} else {
alert("Invalid username or password");
}
});
// Check if user is already logged in
const currentUser = JSON.parse(localStorage.getItem("currentUser"));
if (currentUser) {
window.location.href = currentUser.url;
}