couche de sécu en plus

This commit is contained in:
Baptiste 2022-06-16 14:38:31 +02:00
parent 72037a668b
commit 34b2dbbe03
2 changed files with 55 additions and 50 deletions

View file

@ -9,32 +9,34 @@ $req = $db->query("SELECT * FROM enigma WHERE id = 1");
$r = $req -> fetchAll(PDO::FETCH_ASSOC); $r = $req -> fetchAll(PDO::FETCH_ASSOC);
if(isset($_POST['send'])) { if(isset($_POST['send'])) {
if(isset($_POST['answer']) AND !empty($_POST['answer'])) { if($user['perm'] >= 2) {
$ans = htmlspecialchars($_POST['answer']); if(isset($_POST['answer']) AND !empty($_POST['answer'])) {
$req = $db->prepare("UPDATE enigma SET answer = ? WHERE id = 1"); $ans = htmlspecialchars($_POST['answer']);
$req->execute(array($ans)); $req = $db->prepare("UPDATE enigma SET answer = ? WHERE id = 1");
} $req->execute(array($ans));
if(isset($_POST['points']) AND !empty($_POST['points'])) {
$point = (int) htmlspecialchars($_POST['points']);
$req = $db->prepare("UPDATE enigma SET point = ? WHERE id = 1");
$req->execute(array($point));
}
if(isset($_POST['team']) AND !empty($_POST['team'])) {
switch (htmlspecialchars($_POST['team'])) {
case "t":
$t_int = NULL;
break;
case "t0":
$t_int = 0;
break;
case "t1":
$t_int = 1;
break;
} }
$req = $db->prepare("UPDATE enigma SET team = ? WHERE id = 1"); if(isset($_POST['points']) AND !empty($_POST['points'])) {
$req->execute(array($t_int)); $point = (int) htmlspecialchars($_POST['points']);
$req = $db->prepare("UPDATE enigma SET point = ? WHERE id = 1");
$req->execute(array($point));
}
if(isset($_POST['team']) AND !empty($_POST['team'])) {
switch (htmlspecialchars($_POST['team'])) {
case "t":
$t_int = NULL;
break;
case "t0":
$t_int = 0;
break;
case "t1":
$t_int = 1;
break;
}
$req = $db->prepare("UPDATE enigma SET team = ? WHERE id = 1");
$req->execute(array($t_int));
}
header('Refresh:0');
} }
header('Refresh:0');
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>

View file

@ -19,35 +19,38 @@ if(isset($_GET['del']) AND !empty(['del']))
if(isset($_POST['send'])) { if(isset($_POST['send'])) {
if(isset($_POST['pseudo']) AND !empty($_POST['pseudo']) AND isset($_POST['mdp']) AND !empty($_POST['mdp']) AND isset($_POST['perm']) AND !empty($_POST['perm'])) { if(isset($_POST['pseudo']) AND !empty($_POST['pseudo']) AND isset($_POST['mdp']) AND !empty($_POST['mdp']) AND isset($_POST['perm']) AND !empty($_POST['perm'])) {
$pseudo = htmlspecialchars($_POST['pseudo']);
$mdp = htmlspecialchars($_POST['mdp']);
$perm = htmlspecialchars($_POST['perm']);
switch ($perm) { if($user['perm'] >= 2) {
case "v0": $pseudo = htmlspecialchars($_POST['pseudo']);
$perm_int = 0; $mdp = htmlspecialchars($_POST['mdp']);
break; $perm = htmlspecialchars($_POST['perm']);
case "v1":
$perm_int = 1;
break;
case "v2":
$perm_int = 2;
break;
}
if(strlen($pseudo) <= 50) { switch ($perm) {
$req = $db->prepare("SELECT id FROM admin WHERE pseudo = ?"); case "v0":
$req->execute(array($pseudo)); $perm_int = 0;
$pseudo_exist = $req->rowCount(); break;
if ($pseudo_exist == 0) { case "v1":
$req = $db->prepare("INSERT INTO admin(pseudo, mdp, perm) VALUES(?, ?, ?)"); $perm_int = 1;
$req->execute(array($pseudo, password_hash($mdp, PASSWORD_DEFAULT), $perm_int)); break;
header('refresh:0'); case "v2":
} else { $perm_int = 2;
$error = "pseudo déja utilisé"; break;
}
if(strlen($pseudo) <= 50) {
$req = $db->prepare("SELECT id FROM admin WHERE pseudo = ?");
$req->execute(array($pseudo));
$pseudo_exist = $req->rowCount();
if ($pseudo_exist == 0) {
$req = $db->prepare("INSERT INTO admin(pseudo, mdp, perm) VALUES(?, ?, ?)");
$req->execute(array($pseudo, password_hash($mdp, PASSWORD_DEFAULT), $perm_int));
header('refresh:0');
} else {
$error = "pseudo déja utilisé";
}
} else {
$error = "le pseudo ne doit pas dépasser 50 char";
} }
} else {
$error = "le pseudo ne doit pas dépasser 50 char";
} }
} else { } else {
$error = "Tout les champs doivent être complétés"; $error = "Tout les champs doivent être complétés";