<?php
$connexion = mysql_connect($host = '127.0.0.1' ,$user = 'root' ,$pass = '') or die(mysql_error());
if (isset($_POST['connexion']))
{
	session_start();
	error_reporting(0);
	include ('config/config.php');
	if (!empty($_POST['pseudo']) and !empty($_POST['pass']))
	{
		$pseudo = htmlentities($_POST['pseudo']);
		$pass = htmlentities($_POST['pass']);
		echo $pseudo,'<br>';
		echo $pass,'<br>';
		mysql_select_db($realmd);
		
		$requete = mysql_query("SELECT COUNT(*) AS nb_pseudo FROM account WHERE username='".$pseudo."'") or die (mysql_error());
		$retour_nb_pseudo = mysql_fetch_assoc($requete);
		
		
		if ($retour_nb_pseudo['nb_pseudo'] == 1)
		{
			$compte = mysql_fetch_assoc(mysql_query("SELECT * FROM account WHERE username='".$pseudo."'")) or die (mysql_error());				
			{						
				$sql = mysql_query("SELECT COUNT(*) AS nombre FROM account WHERE sha_pass_hash=SHA1(CONCAT(UPPER('$pseudo'),':',UPPER('$pass')))");
				$sha = mysql_fetch_assoc($sql);
				if ($sha['nombre'] == 1)
				{
						$_SESSION['logged'] = true;
						$_SESSION['id'] = $compte['id'];										
						$_SESSION['pseudo'] = $pseudo;		
						$_SESSION['username'] = $compte['username'];							
						?>							
						<script language="JavaScript">
							<!--
							window.location.href="membre.php"
							//-->
						</script>
						<p>Vous avez ete connecte. <a href="membre.php?page=membre">Entrer dans votre espace membre</a>.</p>
						<?php
				}
				else
				{
					echo '<div class="erreur">Le mot de passe n\'est pas bon.</div>';
				}
			}
		}
		else
		{
			echo '<div class="erreur">Le pseudo n\'existe pas.</div>';
		}
	}
	else
	{
		echo '<div class="erreur">Tout les champs ne sont pas remplis</div>';
	}
}
?>