<?php
	$result = $_SESSION['dbh']->query("SELECT Nom FROM oxg_users");
	if($result=="")
	{
		echo "<font color=red>".decode_lng_text("PASSWORD_MESSAGE")."</font><br>";
	}
	else
	{
		$count=$result->num_rows;
		if($count > 0)
		{
			if(isset( $_SERVER['PHP_AUTH_PW']))
			{
				$AUTH_PW = md5($_SERVER['PHP_AUTH_PW']);
				$PW="";
				$sql_query = "select password, login, nom, prenom, privilege from oxg_users where login='".$_SERVER['PHP_AUTH_USER']."' and password='".$AUTH_PW."'";
				$result=$_SESSION['dbh']->query($sql_query) or mysqli_die()();
				while($tab = $result->fetch_array(MYSQLI_ASSOC))
				{
					if(isset($tab['password']))
					{
						$PW = $tab['password'];
						$NOM = $tab['nom'];
						$PRENOM = $tab['prenom'];
					}
				}
				if( $AUTH_PW != $PW )
				{
					header("status: 401 Unauthorized");
					header("HTTP/1.0 401 Unauthorized");
					header('WWW-authenticate: Basic '.'realm="ACCESS SECURISE APPLICATION"');
					print("Vérification : ERREUR"); 
					exit(0);
				}
			}
			else
			{
				header("status: 401 Unauthorized");
				header("HTTP/1.0 401 Unauthorized");
				header('WWW-authenticate: Basic '.'realm="ACCESS SECURISE APPLICATION"');
				echo "Vous devez vous identifier.";
				exit(0);
			}
		}
	}
?>