Autenticação Shopbox Scripts
by thvinic
HTML
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Exemplo de Autenticação</title>
</head>
<body>
<div>
<label for="username">Usuário:</label>
<input type="text" id="username">
</div>
<div>
<label for="password">Senha:</label>
<input type="password" id="password">
</div>
<button onclick="autenticarLogin()">Login</button>
<script>
function verificarUsuarioLogado() {
const usuarioLogado = localStorage.getItem("usuario");
if (usuarioLogado) {
// Redirecionar para a página inicial
window.location.href = "index.html";
}
}
function autenticarLogin() {
const urlDados = "https://raw.githubusercontent.com/thvinicc/thvinicc.github.io/main/data.html";
fetch(urlDados)
.then(response => response.text())
.then(html => {
const users = {};
const elements = new DOMParser().parseFromString(html, 'text/html').querySelectorAll("div[id^='username']");
elements.forEach(element => {
const username = element.textContent;
const idNumber = element.id.replace("username", "");
const password = new DOMParser().parseFromString(html, 'text/html').querySelector(`#password${idNumber}`).textContent;
users[username] = password;
});
const inputUsername = document.getElementById("username").value;
const inputPassword = document.getElementById("password").value;
// Verifica se o nome de usuário e senha inseridos correspondem a um dos pares coletados
if (users[inputUsername] === inputPassword) {
// Armazena informações do usuário no localStorage
...