<?php
/**
 * Processing Forget password form data:
 * check data then generate new password and send it through SMPT Email
 *
 * PHP version 7.3
 *
 * @package        SMS
 * @version        Release 1.0.0
 * @create_by      Mohammad aljaouni
 * @create_date    10-08-2020
 * @edited_by      Mohammad aljaouni
 * @last_edit_date 10-08-2020
 * @todo           Nothing
 */
ob_start();
session_start();
$chain = "AWdrh78y892Djk*^523*%$#ghgHGHia&%$*)AsfdsLJnLaad";
include("validateLogin.php");
include("includeInformation.php");
if(isset($_POST['backPage']))
	$backLink = $_POST['backPage'];
else
	$backLink = 'users.php';

if(empty($_POST["idUser2"])) {
	header("location:".$backLink."");
  	exit;
}
$idUser = (int) $_POST["idUser2"];
if(empty($_POST['passwordC2']) || empty($_POST['password'])) {
	header("location:users.php?res=19");
	exit;
}
$passwordC2=mysqli_real_escape_string($conn, $_POST['passwordC2']);
$password=mysqli_real_escape_string($conn, $_POST['password']);

if($password != $passwordC2) {
	header("location:users.php?res=7");
	exit;
}
$md5Password = md5($password);
$query  =" UPDATE `user_login` SET";
$query .=" password='".$md5Password."'";
$query .=" WHERE id='".$idUser."'";

$result = mysqli_query($conn, $query);
if($result) {
	header("location:".$backLink."?res=1");
	exit;
}
header("location:".$backLink."?res=2");
exit;	
ob_end_flush();
?>
