<?
include ("connectionADMIN.php");
include ("frames_header.php");

session_start();

$current=$_POST["current"];

$new=$_POST["new"];
$new2=$_POST["retype_new"];


if ($new!=$new2) 
	{
	print "<center>You have typed two differents new password (check your \"Retype Password\" field in order to be the same as \"New Password\"</center><BR><a href=\"modify.php\">Go Back</a>";
	include ("frames_footer.php");
	return;
	}




$pass=md5($current.$_SESSION["login"]);

$requete="SELECT usename from pg_shadow where passwd='md5$pass'";
$stmt=pg_query($c,$requete);
if (pg_num_rows($stmt)==0)
	{
	print "<center>Your current password is not the one you have been entered ! Please check your current password again</center><a href=\"modify.php\">Go Back</a>";
	include ("frames_footer.php");
	return;
	}

$row=pg_fetch_array($stmt);
$USER=$row["usename"];
if (strlen($USER)==0) 
	{
	print "ERROR ...";
	include ("frames_footer.php");
	return;
	}


//$enc="md5$new$USER";
pg_query($c,"begin");

$requete="ALTER USER $USER PASSWORD '$new'";
//pg_query($c,$requete) or die ("Database Error, Password Update Failed");
pg_query($c,$requete) or die (pg_last_error($c));

pg_query($c,"commit");


print "<center><h2>Password succesfuly UPDATED</h2><br>Please Login again <a href=\"login.php\">here</a> with your new password</center>";







include ("frames_footer.php");
?>