J'ai un problème au niveau Authentification

Ali - 21 avril 2014 à 18:18
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 - 24 avril 2014 à 18:34
Bonjour,
j'ai un problème au niveau de la connexion si je me connecte autant que prof il me donne que le login ou le mot de passe incorrecte malgré qu'il est correcte a la base de données quesque je dois faire ?? voila le code
<?php  include('cnx.php');
session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ecole Formation</title>
<meta name="keywords" content="free templates, website templates, CSS, HTML" />
<meta name="description" content="free website template provided by templatemo.com" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.ennui.contentslider.css" rel="stylesheet" type="text/css" media="screen,projection" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
</script>
<style type="text/css">
<!--
.Style1 {
font-size: x-large;
font-weight: bold;
color: #FFFFFF;
}
.Style3 {font-size: 9px}
-->
</style>
</head>
<body>

<div id="templatemo_container">

<div id="templatemo_site_title_wrapper">

<div id="site_title">
<h1>
<a href="index.php" target="_parent"><span>Formation Professionelle</span></a> </h1>
</div>

</div> <!-- end of site title -->

<div id="templatemo_banner">

<div id="one" class="contentslider">
<div class="cs_wrapper">
<div class="cs_slider">

<div class="cs_article">
<a href="#" target="_blank">
<img src="images/article01.jpg" alt="Artist's interpretation of article headline" width="330" height="173" /> </a>

<div class="text">
<h2> <a href="#">Bienvenue</a> </h2>

<p>Maintenant c'est le meilleur moment pour obtenir la formation que vous toujours désirée.
</p>
<a class="readmore" href="#">Read More</a>
</div>
</div><!-- End cs_article -->

<div class="cs_article">
<a href="#" target="_blank">
<img src="images/article02.jpg" alt="Artist's interpretation of article headline" />
</a>

<div class="text">
<h2> <a href="#"></a></h2>
<p>....</p>
<a class="readmore" href="#">Read More</a>
</div>
</div><!-- End cs_article -->

<div class="cs_article">
<a href="#" target="_blank">
<img src="images/article03.jpg" alt="Artist's interpretation of article headline" />
</a>

<div class="text">
<h2> <a href="#"></a> </h2>

<p>....
</p>

<a class="readmore" href="#">Read More</a>
</div>
</div><!-- End cs_article -->

<div class="cs_article">
<a href="#" target="_blank">
<img src="images/article04.jpg" alt="Artist's interpretation of article headline" />
</a>

<div class="text">
<h2> <a href="#">Project Four</a> </h2>

<p>
....
</p>

<a class="readmore" href="#">Read More</a>
</div>
</div><!-- End cs_article -->

</div><!-- End cs_slider -->
</div><!-- End cs_wrapper -->
</div><!-- End contentslider -->

<!-- Site JavaScript -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="js/jquery.ennui.contentslider.js"></script>
<script type="text/javascript">
$(function() {
$('#one').ContentSlider({
width : '860px',
height : '210px',
speed : 800,
easing : 'easeInOutBack'
});
});
</script>
<script src="js/jquery.chili-2.2.js" type="text/javascript"></script>
<script src="js/chili/recipes.js" type="text/javascript"></script>

</div>
<!-- end of banner -->

<div id="templatemo_menu">

<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<div align="center" class="Style1">Connectez-vous ou <a href="inscrire.php" class="lien">Inscrivez-Vous</a> </div>
</ul>

</div>

<div id="templatemo_content">
<div class="section_w920">
<h2 align="left">Authentification étudiant                     <img src="images/templatemo_header_bg.png" width="49" height="40" /> Authentification Enseignant </h2>
</div>

<div class="section_w920">
<table width="100%%" border="0">
<tr>
<td width="37%"><form id="form1" name="form1" method="post" action="">
<table width="100%%" border="1">
<tr>
<td width="44%">Pseudo :</td>
<td width="56%"><input name="t1" type="text" class="champs" id="t1" /></td>
</tr>
<tr>
<td>Mot de passe :</td>
<td><input name="t2" type="password" class="champs" id="t2" /></td>
</tr>
<tr>
<td><input name="b1" type="submit" class="btn_rechrche" id="b1" value="Se Connecter" /></td>
<td><?php

if(isset($_POST['b1']))
{


$pseudo=mysql_real_escape_string(htmlspecialchars(trim($_POST['t1'])));
$pass=mysql_real_escape_string(htmlspecialchars(trim($_POST['t2'])));
$pass=md5($pass);
$dd=mysql_query("select * from etudiant where pseudo='$pseudo' and mdp='$pass'");
$ligne= mysql_fetch_row($dd);

if ($ligne!=0 )
{

$_SESSION['pseudo']=$pseudo;
$_SESSION['id']=$ligne[0];
$_SESSION['nom']=$ligne[1];
$_SESSION['prenom']=$ligne[2];
$_SESSION['dateN']=$ligne[5];
//header("location:liste_cours.php");
echo"<meta HTTp-EQUIV='Refresh' CONTENT='0; URl= Etudiant.php'>";

}else echo 'Login ou Mot de passe incorrect !';

}

?></td>
</tr>
</table>
</form>
</td>
<td width="24%" align="left" valign="middle"> </td>
<td width="38%"><form id="form2" name="form2" method="post" action="">
<table width="100%%" border="1">
<tr>
<td width="44%">Pseudo :</td>
<td width="56%"><input name="t3" type="text" class="champs" id="t3" /></td>
</tr>
<tr>
<td>Mot de passe :</td>
<td><input name="t4" type="password" class="champs" id="t4" /></td>
</tr>
<tr>
<td><input name="b2" type="submit" class="btn_rechrche" id="b2" value="Se Connecter" /></td>
<td><?php

if(isset($_POST['b2']))
{

$login=mysql_real_escape_string(htmlspecialchars(trim($_POST['t3'])));
$passe=mysql_real_escape_string(htmlspecialchars(trim($_POST['t4'])));
$passe=md5($passe);
$d=mysql_query("select * from prof where login='$login' and passe='$passe'");
$l= mysql_num_rows($d);

if ($l!=0 )
{

$_SESSION['prof'] = $login;
$s=mysql_query("select max(IdProf),NomProf,PrenomProf from prof where login='".$_SESSION['prof']."'");
$r= mysql_fetch_array($s);
$_SESSION['Id_Prof']=$r[0];
$_SESSION['Nom_Prof']=$r[1];
$_SESSION['Prenom_Prof']=$r[2];
//session_destroy();
//header("Location: ajouter_cours.php");

echo"<meta HTTp-EQUIV='Refresh' CONTENT='0; URl= ajouter_cours.php'>";

}else echo 'Login ou Mot de passe incorrect !';

}

?></td>
</tr>
</table>
</form>
</td>
<td width="1%"> </td>
</tr>
</table>
<p> </p>
<!-- <div class="button_01"><a href="#">Read more</a></div> -->

<div class="cleaner"></div>

</div>

</div>



</div> <!-- end of container -->

</body>
</html>

4 réponses

jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
21 avril 2014 à 21:09
Bonjour.
Plutôt que mysql_fetch_row
Utilises num_rows et fetch_array.


0
pouvez vous m'écrire toute la syntaxe ???
0
svp j'ai le problème au niveau de la parti prof non pas étudiant :/
0
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
21 avril 2014 à 21:31
Aparté :
L'extension "mysql" est dépréciée et ne sera plus maintenue sous peu, essayes de te mettre à jour en utilisant "mysqli" par exemple.
0
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
22 avril 2014 à 17:36
bonjour,

if(isset($_POST['b2'])){

$login=mysql_real_escape_string(htmlspecialchars(trim($_POST['t3'])));
$passe=mysql_real_escape_string(htmlspecialchars(trim($_POST['t4'])));
$passe=md5($passe);

// Sépare les requetes de la commande pour la lancer...ça permet de vérifier si elle est bonne...

$sql = "select * 
           from prof 
           where login='$login' 
           and passe='$passe'";

// Et vas verifier que ta requête fonctionne en DIRECTE dans ta BDD
Echo $sql;

$d=mysql_query($sql);
$nbl= mysql_num_rows($d);

if ($nbl==1){
 // Ici le code si c'est bon...

}else{
 // Le code si c'est faut.
Echo "Nombre de lignes retournées :  ".$nbl;



}




0
select * from prof where login='prof1' and passe='0b4e7a0e5fe84ad35fb5f95b9ceeac79'
Notice: Undefined variable: l in C:\Program Files (x86)\EasyPHP-12.1\www\Site sans nom 18\login.php on line 226
Login ou Mot de passe incorrect !
voila l'erreurs qui se produit , le problème que j'ai il change le mot de passe que je fais entrer et je sais pas pourquoi ?
normalement j'ai tapé aaaa et il m'affiche que j'ai fais entrer une serie de nombres et lettres
0
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
23 avril 2014 à 13:05
e problème que j'ai il change le mot de passe que je fais entrer et je sais pas pourquoi ?
Ben... par ce que tu lui demandes de l'encoder...
$passe=mysql_real_escape_string(htmlspecialchars(trim($_POST['t4'])));
$passe=md5($passe);


http://www.php.net/manual/fr/function.md5.php

Le tout c'est de savoir... comment ton mot de pass est stocké dans ta BDD....
0
mot de passe stocké autant que varchar
0
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
23 avril 2014 à 14:41
Tes password ... ils sont écrits en CLAIR dans ta BDD ?
C'est à dire ... tu as TOTO ou un truc du genre 0b4e7a0e5fe84ad35fb5f95b9ceeac79' ????
0
un truc du genre 0b4e7a0e5fe84ad35fb5f95b9ceeac79' ??
0
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
Modifié par jordane45 le 24/04/2014 à 18:34
Bon..

J'ai remanié un peu ton code..

Déjà.. j'ai séparé le code HTML du Code PHP ...
Cela rend le code plus facile à lire et à debuguer.

Testes le :
<?php  
include('cnx.php');
session_start();

//----------------------------------------------
// Mettre tout le code PHP ICI
//----------------------------------------------
 $msginfo = "";
 $msginfo2 = "";
 
if(isset($_POST['b1'])){
 $pseudo=mysql_real_escape_string(htmlspecialchars(trim($_POST['t1'])));
 $pass=mysql_real_escape_string(htmlspecialchars(trim($_POST['t2'])));
 $pass=md5($pass);
 $dd=mysql_query("select * from etudiant where pseudo='$pseudo' and mdp='$pass'");
 $ligne= mysql_fetch_row($dd);
if ($ligne!=0 ){
 $_SESSION['pseudo']=$pseudo;
 $_SESSION['id']=$ligne[0];
 $_SESSION['nom']=$ligne[1];
 $_SESSION['prenom']=$ligne[2];
 $_SESSION['dateN']=$ligne[5];
 //header("location:liste_cours.php");
    $msginfo = "<meta HTTp-EQUIV='Refresh' CONTENT='0; URl= Etudiant.php'>";   
}else{
   $msginfo = 'Login ou Mot de passe incorrect !';
}
}


if(isset($_POST['b2'])){

$login=mysql_real_escape_string(htmlspecialchars(trim($_POST['t3'])));
$passe=mysql_real_escape_string(htmlspecialchars(trim($_POST['t4'])));
  echo "<br> Passe : ".$passe."<br>";
$passe=md5($passe);
  echo "<br> Passe MD5 : ".$passe."<br>";
$sql = "select * 
           from prof 
           where login='$login' 
           and passe='$passe'";

Echo "<p>Requête => <br>".$sql."</p>";

$d=mysql_query($sql);
$nbl= mysql_num_rows($d);

if ($nbl!=0 ){
 $_SESSION['prof'] = $login;
 $s=mysql_query("select IdProf,NomProf,PrenomProf from prof where login='".$_SESSION['prof']."'");
 $r= mysql_fetch_array($s);
 $_SESSION['Id_Prof']=$r[0];
 $_SESSION['Nom_Prof']=$r[1];
 $_SESSION['Prenom_Prof']=$r[2];

    $msginfo2="<meta HTTp-EQUIV='Refresh' CONTENT='0; URl= ajouter_cours.php'>";   

}else{
   $msginfo2 = 'Login ou Mot de passe incorrect !';
}

}



//----------------------------------------------
// ET en-dessous ... le HTML
//----------------------------------------------
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ecole Formation</title>
<meta name="keywords" content="free templates, website templates, CSS, HTML" />
<meta name="description" content="free website template provided by templatemo.com" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.ennui.contentslider.css" rel="stylesheet" type="text/css" media="screen,projection" />
<script language="javascript" type="text/javascript">
function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
</script>
<style type="text/css">
<!--
.Style1 {
 font-size: x-large;
 font-weight: bold;
 color: #FFFFFF;
}
.Style3 {font-size: 9px}
-->
</style>
</head>
<body>

<div id="templatemo_container">

 <div id="templatemo_site_title_wrapper">
    
     <div id="site_title">
            <h1>
                <a href="index.php" target="_parent"><span>Formation Professionelle</span></a>            </h1>
     </div>
    
</div> <!-- end of site title -->
    
 <div id="templatemo_banner">

     <div id="one" class="contentslider">
            <div class="cs_wrapper">
                <div class="cs_slider">
                
                    <div class="cs_article">
                        <a href="#" target="_blank">
                         <img src="images/article01.jpg" alt="Artist's interpretation of article headline" width="330" height="173" />                        </a>
                        
          <div class="text">
                            <h2> <a href="#">Bienvenue</a> </h2>
                            
                            <p>Maintenant c'est le meilleur moment pour obtenir la formation que vous toujours désirée.
                             </p>
                            <a class="readmore" href="#">Read More</a>
                      </div>
                 </div><!-- End cs_article -->
                    
                    <div class="cs_article">
                        <a href="#" target="_blank">
                        <img src="images/article02.jpg" alt="Artist's interpretation of article headline" />
                        </a>
                        
                        <div class="text">
                            <h2> <a href="#"></a></h2>
                            <p>....</p>
                           <a class="readmore" href="#">Read More</a>
                        </div>
                  </div><!-- End cs_article -->
                    
                    <div class="cs_article">
                        <a href="#" target="_blank">
                        <img src="images/article03.jpg" alt="Artist's interpretation of article headline" />
                        </a>
                        
                        <div class="text">
                            <h2> <a href="#"></a> </h2>
                            
                            <p>....
                                                 </p>
                            
                            <a class="readmore" href="#">Read More</a>
                     </div>
                 </div><!-- End cs_article -->
                    
                    <div class="cs_article">
                        <a href="#" target="_blank">
                        <img src="images/article04.jpg" alt="Artist's interpretation of article headline" />
                        </a>
                        
                        <div class="text">
                            <h2> <a href="#">Project Four</a> </h2>
                            
                            <p>
                            ....
                            </p>
                            
                            <a class="readmore" href="#">Read More</a>
                     </div>
                 </div><!-- End cs_article -->
              
                </div><!-- End cs_slider -->
            </div><!-- End cs_wrapper -->
        </div><!-- End contentslider -->

 <!-- Site JavaScript -->
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
 <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
 <script type="text/javascript" src="js/jquery.ennui.contentslider.js"></script>
 <script type="text/javascript">
   $(function() {
    $('#one').ContentSlider({
     width : '860px',
     height : '210px',
     speed : 800,
     easing : 'easeInOutBack'
    });
   });
  </script>
 <script src="js/jquery.chili-2.2.js" type="text/javascript"></script>
 <script src="js/chili/recipes.js" type="text/javascript"></script>

    </div> 
    <!-- end of banner -->
    
    <div id="templatemo_menu">
    
     <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <div align="center" class="Style1">Connectez-vous ou <a href="inscrire.php" class="lien">Inscrivez-Vous</a>                         </div>
     </ul>
    
    </div>
    
    <div id="templatemo_content">
<div class="section_w920">
       <h2 align="left">Authentification  étudiant                           
     <img src="images/templatemo_header_bg.png" width="49" height="40" /> Authentification Enseignant 
    </h2>
      </div>
        
<div class="section_w920">
  <table width="100%%" border="0">
            <tr>
              <td width="37%"><form id="form1" name="form1" method="post" action="">
                <table width="100%%" border="1">
                  <tr>
                    <td width="44%">Pseudo :</td>
                    <td width="56%"><input name="t1" type="text" class="champs" id="t1" /></td>
                  </tr>
                  <tr>
                    <td>Mot de passe :</td>
                    <td><input name="t2" type="password" class="champs" id="t2" /></td>
                  </tr>
                  <tr>
                    <td><input name="b1" type="submit" class="btn_rechrche" id="b1" value="Se Connecter" /></td>
                    <td>
                     <?php Echo $msginfo;?>
     </td>
                  </tr>
                </table>
                            </form>
              </td>
              <td width="24%" align="left" valign="middle"> </td>
              <td width="38%"><form id="form2" name="form2" method="post" action="">
                <table width="100%%" border="1">
                  <tr>
                    <td width="44%">Pseudo :</td>
                    <td width="56%"><input name="t3" type="text" class="champs" id="t3" /></td>
                  </tr>
                  <tr>
                    <td>Mot de passe :</td>
                    <td><input name="t4" type="password" class="champs" id="t4" /></td>
                  </tr>
                  <tr>
                    <td><input name="b2" type="submit" class="btn_rechrche" id="b2" value="Se Connecter" /></td>
                    <td>
     <?php
                     echo $msginfo2;
     ?>
    </td>
                  </tr>
                </table>
              </form>
              </td>
              <td width="1%"> </td>
        </tr>
          </table>
          <p> </p>
        <!-- <div class="button_01"><a href="#">Read more</a></div> -->
            
            <div class="cleaner"></div>
            
      </div>
    
  </div>
    
    <div id="templatemo_footer">
        
        <ul class="footer_menu">
            <li><a href="index.php">Accueil</a></li>
        <li><a href="#">About</a></li>
            <li><a href="#">News</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Gallery</a></li>
            <li class="last_menu"><a href="contact.php">Contact</a></li>
        </ul>
    </div> 
<div style="text-align: center; font-size: 0.75em;"></div>
<!-- end of footer -->

</div> <!-- end of container -->

</body>
</html>



Avant de poser une question, merci de lire la charte du site.
Cordialement, Jordane
0
Rejoignez-nous