fix password problem

This commit is contained in:
2026-03-19 13:24:13 +01:00
parent c7f3158d5b
commit 852ed54fba
3 changed files with 32 additions and 29 deletions
+23 -18
View File
@@ -1,5 +1,5 @@
const hashedAdminPassword = "7215d31f702fe2faf2a7df114c6427007bd254740c6b9cbaa2a5505060088929";
async function SqlRequest(action, params = {}) { async function SqlRequest(action, params = {}) {
try { try {
@@ -92,23 +92,28 @@ async function joinGameAsAdmin(gameId) {
// Récupérer le formulaire de admin-login // Récupérer le formulaire de admin-login
const adminLoginForm = document.getElementById('admin-login-form'); const adminLoginForm = document.getElementById('admin-login-form');
if (adminLoginForm) { adminLoginForm.addEventListener('submit', async function(event) {
adminLoginForm.addEventListener('submit', async function(event) { event.preventDefault();
event.preventDefault(); // Désactiver le bouton pour éviter les soumissions multiples
const password = document.getElementById('admin-password').value; const password = this.querySelector('input[type="password"]').value;
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const gameId = urlParams.get('game_id'); const gameId = urlParams.get('game_id');
const response = await SqlRequest('adminLogin', { // Vérification du mot de passe
password: password, const hashedInputPassword = CryptoJS.SHA256(password).toString();
game_id: gameId
});
if (response.success) { if (hashedInputPassword !== hashedAdminPassword) {
window.location.href = `admin-game.html?game_id=${gameId}`; alert("Mot de passe incorrect. Veuillez réessayer.");
} else { return;
alert("Identifiants incorrects. Veuillez réessayer."); }
}
}); // Requete SQL pour définir l'utilisateur comme admin du jeu
} const response = await SqlRequest('adminLogin', {game_id: gameId});
if (response.success) {
window.location.href = `admin-game.html?game_id=${gameId}`; // Redirige vers la page d'administration du jeu
} else {
alert("Erreur lors de la connexion. Veuillez réessayer."); // Affiche une alerte en cas d'erreur
}
});
+8 -10
View File
@@ -227,17 +227,15 @@ switch ($action) {
break; break;
case 'adminLogin': case 'adminLogin':
$stmt = $pdo->prepare("SELECT * FROM admins WHERE game_id = ? AND password = ?"); // On vérifie si l'utilisateur est déjà admin
$stmt->execute([$params['game_id'], $params['password']]); session_start();
$admin = $stmt->fetch(PDO::FETCH_ASSOC); if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
if ($admin) { $response = ['success' => true, 'message' => 'Déjà connecté en tant qu\'admin'];
$response = ['success' => true]; break;
session_start();
$_SESSION['admin_logged_in'] = true;
$_SESSION['game_id'] = $params['game_id'];
} else {
$response = ['error' => 'Mot de passe incorrect'];
} }
// On dit que l'utilisateur est admin
$_SESSION['admin_logged_in'] = true;
$response = ['success' => true, 'message' => 'Connexion admin réussie'];
break; break;
case 'is_admin': case 'is_admin':
+1 -1
View File
@@ -5,7 +5,7 @@
</head> </head>
<body> <body>
<h1>Admin Login</h1> <h1>Admin Login</h1>
<form id="adminLoginForm"> <form id="admin-login-form">
<label for="adminPassword">Mot de passe administrateur :</label> <label for="adminPassword">Mot de passe administrateur :</label>
<input type="password" id="adminPassword" name="adminPassword" required> <input type="password" id="adminPassword" name="adminPassword" required>
<br><br> <br><br>