From c75da06bb039de2a43f21b6e853a72745f753dca Mon Sep 17 00:00:00 2001
From: Greg Burri <greg.burri@gmail.com>
Date: Mon, 21 Sep 2009 14:39:30 +0200
Subject: [PATCH] =?utf8?q?MOD=20#138=20:=20Stockage=20des=20passwords=20ha?=
 =?utf8?q?sh=C3=A9s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 index.php               | 2 +-
 php/controller.php      | 4 ++--
 php/pages/bienvenue.php | 2 +-
 php/panel.php           | 2 +-
 php/participant.php     | 3 ++-
 php/update_db.php       | 3 ++-
 6 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/index.php b/index.php
index e41a32e..eb24013 100644
--- a/index.php
+++ b/index.php
@@ -28,7 +28,7 @@ $panel = new Panel($participant);
 
 if ($controller->nouvel_inscrit)
    $page = "bienvenue";
-   
+
 echo '<?xml version="1.0" encoding="UTF-8"?>';
 
 ?>
diff --git a/php/controller.php b/php/controller.php
index f3fd468..cad4352 100644
--- a/php/controller.php
+++ b/php/controller.php
@@ -48,7 +48,7 @@ class Controller
                array(
                   $id,
                   $_POST['pseudo'],
-                  $_POST['pass1'],
+                  sha1($_POST['pass1']),
                   $_POST['clan_nom'],
                   $_POST['clan_tag'],
                   $_POST['nom'],
@@ -78,7 +78,7 @@ class Controller
          {
             pg_query("BEGIN");
             pg_query_params("UPDATE participants SET pseudo = $1 WHERE id = $2", array($_POST['pseudo'], $this->participant->info->id));
-            pg_query_params("UPDATE participants SET password = $1 WHERE id = $2", array($_POST['pass1'], $this->participant->info->id));
+            pg_query_params("UPDATE participants SET password = $1 WHERE id = $2", array(sha1($_POST['pass1']), $this->participant->info->id));
             pg_query_params("UPDATE participants SET clan_nom = $1 WHERE id = $2", array($_POST['clan_nom'], $this->participant->info->id));
             pg_query_params("UPDATE participants SET clan_tag = $1 WHERE id = $2", array($_POST['clan_tag'], $this->participant->info->id));
             pg_query_params("UPDATE participants SET nom = $1 WHERE id = $2", array($_POST['nom'], $this->participant->info->id));
diff --git a/php/pages/bienvenue.php b/php/pages/bienvenue.php
index b808985..7e14f00 100644
--- a/php/pages/bienvenue.php
+++ b/php/pages/bienvenue.php
@@ -1,7 +1,7 @@
 <?php # coding: utf-8 ?>
 
 <p><em>Toute l'équipe de la Corcelles-LAN vous souhaite la bienvenue !!</em></p>
-<p>Votre inscription a été enregistré, voici quelques liens utiles :
+<p>Votre inscription a été enregistrée, voici quelques liens utiles :
 <ul>
    <li><a href="inscription.html">Modification des informations personnelles</a></li>
    <li><a href="jeux_joues.html">Voter pour un ou plusieurs jeux</a></li>
diff --git a/php/panel.php b/php/panel.php
index 54b1b53..d07bb6c 100644
--- a/php/panel.php
+++ b/php/panel.php
@@ -55,7 +55,7 @@ class Panel
          <p>login / pass</p>
          <p><input type="hidden" name="log" value="1" /></p>
          <p><input type="text" name="pseudo" size="10" maxlength="30" /></p>
-         <p><input type="password" name="password" size="10" maxlength="10" /></p>
+         <p><input type="password" name="password" size="10" maxlength="15" /></p>
          <p><input type="submit" value="oki" class="submitInvisible" /></p>
          </form>
          ';
diff --git a/php/participant.php b/php/participant.php
index ef92a06..e2b47be 100644
--- a/php/participant.php
+++ b/php/participant.php
@@ -16,6 +16,7 @@ class Participant
      * 1) $v1 = NULL, $v2 = NULL : participant non-valide
      * 2) $v1 = id, $v2 = NULL : la participant existe et est chargé à partir de son id
      * 3) $v1 = pseudo, $v2 = password : le participant existe et est chargé à partir de son pseudo et de son password
+     * Le mot de passe est donné en clair.
      */
    public function Participant($v1=NULL, $v2=NULL)
    {	   
@@ -25,7 +26,7 @@ class Participant
 
 		if (is_string($v1) && is_string($v2)) # Aucun des arguments n'est vide alors c'est le pseudo et le password qui ont été transmis
       {
-			$res = pg_query_params("SELECT id FROM participants WHERE pseudo = $1 AND password = $2", array($v1, $v2));
+			$res = pg_query_params("SELECT id FROM participants WHERE pseudo = $1 AND password = $2", array($v1, sha1($v2)));
       }
 		else # Sinon c'est l'id
 			$res = pg_query_params("SELECT id FROM participants WHERE id = $1", array($v1));
diff --git a/php/update_db.php b/php/update_db.php
index be2c041..a2d9ffe 100644
--- a/php/update_db.php
+++ b/php/update_db.php
@@ -34,13 +34,14 @@ function creer_db()
         UNIQUE (nom)
       );
    ");
+   // participants.password est un hash calculé à l'aide de sha1().
    pg_query("
       CREATE TABLE participants (
         id int NOT NULL,
         pseudo varchar(50) DEFAULT NULL,
         clan_nom varchar(30) DEFAULT NULL,
         clan_tag varchar(10) DEFAULT NULL,
-        password varchar(10) DEFAULT NULL,
+        password char(40) DEFAULT NULL,
         nom varchar(30) DEFAULT NULL,
         prenom varchar(30) DEFAULT NULL,
         age varchar(30) DEFAULT NULL,
-- 
2.49.0