<?Php
session_start();

$ak=$_POST['ak'];
$userid=$_POST['userid'];
$todo=$_POST['todo'];
$password=$_POST['password'];
$password2=$_POST['password2'];

?>
<!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>
<title>(Type a title for your page here)</title>
</head>

<body>
<?Php
//$userid=mysql_real_escape_string($userid);
//$ak=mysql_real_escape_string($ak);


$tm=time()-86400;


$sql=$con->prepare("SELECT userid  FROM tass_key WHERE pkey='$ak' and userid='$userid' and time > '$tm' and status='pending'");
$sql->bind_param('s',$userid);
$sql->bind_param('s',$ak);
$sql->execute();
$no=$sql->num_rows;
$sql->close();
//echo " No of records = ".$no; 

if($no <>1){
echo "<center><font face='Verdana' size='2' color=red><b>Wrong activation </b></font> "; 
exit;
}

////////////////////// Show the change password form //////////////////


if(isset($todo) and $todo=="new-password"){
//$password=mysql_real_escape_string($password);

//Setting flags for checking
$status = "OK";
$msg="";

			


if ( strlen($password) < 3 or strlen($password) > 8 ){
$msg=$msg."Password must be more than 3 char legth and maximum 8 char lenght<BR>";
$status= "NOTOK";}					

if ( $password <> $password2 ){
$msg=$msg."Both passwords are not matching<BR>";
$status= "NOTOK";}					



if($status<>"OK"){ 
echo "<font face='Verdana' size='2' color=red>$msg</font><br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
}else{ // if all validations are passed.
$password=md5($password); // Encrypt the password before storing

// Update the new password now //
$count=$con->prepare("update plus_signup set password='$password' where userid='$userid'");
$count->execute();
$no=$count->num_rows;
$count->close();
//echo " No of records = ".$no; 
if($no==1){

$tm=time();
// Update the key so it can't be used again. 
$count=$con->prepare("update plus_key set status='done' where pkey='$ak' and userid='$userid'  and status='pending'");
$count->execute(); 

echo "<font face='Verdana' size='2' ><center>Thanks <br> Your new password is stored successfully. </font></center>";
}else{echo "<font face='Verdana' size='2' color=red><center>Sorry <br> Failed to store new password Contact Site Admin</font></center>";
} // end of if plus_signup is updated with new password
} // end of if status <> 'OK'
}


?>
<center><a href=login.php>Login</a>
<br><br><a href='http://www.plus2net.com' rel="nofollow">PHP SQL HTML free tutorials and scripts</a></center> 

</body>

</html>
