session_start();
include 'inc/connect.php';
include 'inc/sysinfo.php';
include 'inc/functions.php';
// if the user is logged on take them to login area
if (isset($_SESSION['myid'])) {
header("location:myprofile.php");
}
// password reset action
if (isset($_POST['resetpassword'])) {
// filter POST data
require_once 'htmlpurifier/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$email = $purifier->purify($_POST['email']);
$resultemail=mysqli_query($link, "select * from `users` where email LIKE '$email' LIMIT 1");
if (mysqli_num_rows($resultemail)=='0'){
$note="The email address you entered does not exist";
$notecolor="danger";
$noteicon="ban";
} else {
// get user id
$resulttheirid=mysqli_query($link, "select * from `users` where email LIKE '$email' LIMIT 1");
while ($rowtheirid=mysqli_fetch_array($resulttheirid)){
$theirid=$rowtheirid['id'];
$theirname=$rowtheirid['firstname'];
}
$token=rand(00000000000,9999999999);
$sql = "UPDATE users SET token='$token' WHERE id='$theirid'";
mysqli_query($link, $sql);
$mailbody="Hi ".$theirname.",
";
$mailbody=$mailbody."Please click on this link to reset your password: ".$sysdomain."/reset.php?email=".$email."&token=".$token."
";
$mailbody=$mailbody.$sysname."
";
$mailbody=$mailbody.$sysemail;
SendEmail($email, 'Password Reset', $mailbody);
$note="Please check your email for reset instructions";
$notecolor="success";
$noteicon="check";
}
}
?>