File "nouveau_password.php"

Full Path: /home/analogde/www/DOSSIER/Massage_admin/nouveau_password.php
File size: 7.48 KB
MIME-type: text/x-php
Charset: utf-8

<?php

	session_start ();
	
	if (!isset($_SESSION['nom']) && !isset($_SESSION['password']))
	{  
			header("Location: login.php");   
	}

	include('database.php');
	DB_connexion(); 
	//error_reporting(0);

	$val1 = "";
	$val2 = "";
	$val3 = "";
	
	$redirection = "";
		
	if(isset($_POST['submit']))
	{ 
		if(isset($_POST['verrou']) && $_POST['verrou'] == "ok")
		{		
				$ancien_mdp = $_POST['ancien_mdp']; 
				$nouveau_mdp = $_POST['nouveau_mdp'];
				$valide_mdp = $_POST['valide_mdp'];
					
				if($_SESSION['nom'] == "admin")
				{
					$client = $_POST['client']; 
					$pieces = explode(" ", $client);	
					$nom = $pieces[0]; 	
					$prenom = $pieces[1]; 		
				}
				else {  $nom = $_SESSION['nom'];
				        $prenom = $_SESSION['prenom'];
					 }
				
				$sql = "SELECT * FROM client WHERE nom ='$nom' and prenom ='$prenom' ";	
				mysqli_query($connexion, "SET NAMES 'utf8'");	
				$result = mysqli_query($connexion, $sql );	
				$data = mysqli_fetch_assoc($result);
		 
				if($ancien_mdp == $data['password'])
				{ 	$val = "0";
					$sql="UPDATE client SET password='$nouveau_mdp' , init_pass ='$val' WHERE nom ='$nom' and prenom ='$prenom'";
					//echo $sql;
					$result = mysqli_query($connexion, $sql );	
					echo 'Modification du mot de passe effectuée avec succés'; 
					echo '<br><br>';
					header("Location: login.php");
	           }
		  else {  
			    	echo 'Le mot de passe actuel n\'est pas valide'; 
					echo '<br><br>'; 
			   }  
		}
	}	

?>


<!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>Réservation</title>
</head>		
	
<script>

function valider() 
{ 
		var verif = true;
		var msg_erreur = new Array;
	   
		var ancien_mdp = document.getElementById("ancien_mdp").value;
		var nouveau_mdp = document.getElementById("nouveau_mdp").value;
		var valide_mdp = document.getElementById("valide_mdp").value;
	 
		var caracteres = /^[0-9a-zA-Z]+$/;  
	   
		if(ancien_mdp == '' || nouveau_mdp == '' || valide_mdp == ''  )
		{	
			verif = false;
			//msg_erreur[] = "Pas de champs vide !";
			msg_erreur.push("Pas de champs vide !.");
		}
	 
		var minlength = 4;  
		var maxlength = 8;  
  
		if(nouveau_mdp.length < minlength || valide_mdp.length > maxlength)  
		{	
			verif = false;
			//msg_erreur[] = "Longueur du password insuffisante ! [4 - 8] !";
			msg_erreur.push("Longueur du password insuffisante ! [4 - 8] !.");
		}
		
		var retour1 = nouveau_mdp.match(caracteres);
		var retour2 = valide_mdp.match(caracteres);
		
		if(retour1 == null || retour2 == null)
		{
			verif = false;
			//msg_erreur[] = "Caractères non autorisés !";
			msg_erreur.push("Caractères non autorisés !.");
		}
		
		if(nouveau_mdp != valide_mdp)
		{
			verif = false;
			//msg_erreur[] = "Caractères non autorisés !";
			msg_erreur.push("Le password et sa confirmation ne sont pas identiques !.");
		}

		if(verif == true)
		{ 
			document.getElementById('verrou').value="ok";
		}
 	
		if(verif == false)
		{ 
			var affiche = msg_erreur.join("\n");
			alert(affiche);
			document.getElementById('verrou').value="erreur";
		}	
  
}
/*

function valider_admin() 
{ 
	   var verif = true;
	   var msg_erreur = new Array;
	   
	   var list = document.getElementById("client");
	   var indx = list.selectedIndex;
	   
	   if(indx < 0)
	   {	verif = false;
			msg_erreur[1] = "Choisir un utilisateur !";
	   }
	   
	  var ancien_mdp = document.getElementById("ancien_mdp").value;
	  var nouveau_mdp = document.getElementById("nouveau_mdp").value;
	  var valide_mdp = document.getElementById("valide_mdp").value;

	  //alert(ancien_mdp + nouveau_mdp + valide_mdp );
	   
	  if(ancien_mdp == '' || nouveau_mdp == '' || ancien_mdp == ''  )
	  {	verif = false;
	  	msg_erreur[2] = "Pas de champs vide !";
	  }
	   
	  if(verif == true)
 	  { document.getElementById('verrou').value="ok";
 	  }
 	
	  if(verif == false)
 	  { var affiche = msg_erreur.join("\n");
	    alert(affiche);
		document.getElementById('verrou').value="erreur";
 	  }	
  
}

function valider_utilisateur() 
{ 
	  var verif = true;
	  var msg_erreur = new Array;
	   
	  var ancien_mdp = document.getElementById("ancien_mdp").value;
	  var nouveau_mdp = document.getElementById("nouveau_mdp").value;
	  var valide_mdp = document.getElementById("valide_mdp").value;

	  //alert(ancien_mdp + nouveau_mdp + valide_mdp );
	   
	  if(ancien_mdp == '' || nouveau_mdp == '' || ancien_mdp == ''  )
	  {	verif = false;
	  	msg_erreur[2] = "Pas de champs vide !";
	  }
	   
	  if(verif == true)
 	  { document.getElementById('verrou').value="ok";
 	  }
 	
	  if(verif == false)
 	  { var affiche = msg_erreur.join("\n");
	    alert(affiche);
		document.getElementById('verrou').value="erreur";
 	  }	
  
}*/
</script>	

<style>

p {
  margin-top: 0px;
}
 
fieldset {
  margin-bottom: 15px;
  padding: 10px;
}
 
legend {
  padding: 0px 3px;
  font-weight: bold;
  font-variant: small-caps;
}
 
label {
  width: 210px;
  display: inline-block;
  vertical-align: top;
  margin: 6px;
}
 
em {
  font-weight: bold;
  font-style: normal;
  color: #f00;
}
 
input:focus {
  background: #eaeaea;
}
 
input, textarea {
  width: 249px;
}
 
textarea {
  height: 100px;
}
 
select {
  width: 254px;
}
 
input[type=checkbox] {
  width: 10px;
}
 
input[type=submit] {
  width: 150px;
  padding: 10px;
}

</style>

</head>

<body>

	<form action="#" name ="form_password" method="post">
	<input type="hidden" name="verrou" id="verrou" value="">
	
<?php
	if($_SESSION['nom'] == "admin")
	{
		echo '<input type="hidden" name="mode" id="mode" value="admin">';
	}
	else
	{
		echo '<input type="hidden" name="mode" id="mode" value="utilisateur">';
	}
?>	
	
    <br>
    <br>

	<p><i>Complétez les champs suivants afin de changé votre mot de passe. Tous les champs </i><em>*</em> sont <em>obligatoires</em></p>
	<fieldset>
    <legend>Changer votre mot de passe</legend>

<?php
/*	
	if($_SESSION['nom'] == "admin")
	{	echo '<label for="client">Utilisateur <em>*</em></label>';
		echo '  <select size = "10" STYLE="width:300" id = "client" name="client">';
		$sql = 'SELECT * FROM client';
		mysqli_query($connexion, "SET NAMES 'utf8'");	
		$result = mysqli_query($connexion, $sql );
		$tab_nom = array();
		$tab_prenom = array();
	
		$ptr = 0;
			
		while ($data = mysqli_fetch_assoc ($result))
		{
			$tab_nom[$ptr] = $data['nom'];
			$tab_prenom[$ptr] = $data['prenom'];
			$ptr = $ptr + 1;
		}		

		for( $i=0; $i < count($tab_nom) ; $i++)
		{
			$tmp = $tab_nom[$i] . " " .$tab_prenom[$i];
			echo '<option value="' .$tmp. '">' .$tmp. '</option>'; 
		}
		
		echo '</select><br><br>';
	}*/
?>
    
    <label for="ancien_mdp">Mot de passe <em>*</em></label>
    <input type="text" id = "ancien_mdp" name = "ancien_mdp" maxlength="8" value = "<?php echo $val1; ?>" ><br>
      
    <label for="nouveau_mdp">Nouveau mot de passe <em>*</em></label>
    <input type="text" id="nouveau_mdp" name = "nouveau_mdp" maxlength="8" value = "<?php echo $val2; ?>"> De 4 à 8 Caractères Alphanumériques [AZ-az-09]<br>

    <label for="valide_mdp">Confirmation du mot de passe <em>*</em></label>
    <input type="text" id="valide_mdp" name="valide_mdp" maxlength="8" value="<?php echo $val3; ?>"><br>
      
  	</fieldset>
<?php 
	echo '<p><input type="submit" name="submit" value="Soummettre" onclick="valider()" >';
?>  
	</form>
	<br />
	<br />
<?php	
	/*if( $redirection == "ok")
	{
		echo '<a href="login.php">Connecter vous avec votre nouveau mot de passe personnel.</a>'; 
	}*/
?>
</body>
</html>