<?PHP 
include "connection.php";
if (isset($_POST['change_pass'])) {
	// fetch token from email click
if (isset($_GET['token'])) {
	// store token in a variable
	$token = $_GET['token'];
	// fetch value from form 
	$newpassword = mysqli_real_escape_string($conn, $_POST['newpassword']);
	$conf_pass = mysqli_real_escape_string($conn, $_POST['cpassword']);
	// hash password ofter submiting form
  $pass = password_hash($newpassword, PASSWORD_BCRYPT);
  $cpass = password_hash($conf_pass, PASSWORD_BCRYPT);

  if ($newpassword === $conf_pass) {
  	$update_query = "UPDATE user_admin SET password = '$pass' WHERE token='$token' ";
  	$run_query = mysqli_query($conn, $update_query);

  	if ($run_query) {
	 echo '<script type="text/javascript">';
 	 echo 'setTimeout(function () { swal("Passsword Updated Successsfully!"," you will redirect login Page","success");';
 	 echo '}, 100);</script>';
	 header('Refresh:4; login.php');
  	}

  }else{
  	echo '<script type="text/javascript">';
    echo 'setTimeout(function () { swal("Warning!","Passsword are not matching","warning");';
    echo '}, 100);</script>';
  }

}else{
   echo '<script type="text/javascript">';
   echo 'setTimeout(function () { swal("Warning!","Passsword are not matching","warning");';
   echo '}, 100);</script>';
	}
 }
?>