<?php
// Include database connection and functions here.
include 'db_connect.php';
include 'functions.php';

// The hashed password from the form
$password = $_POST['p'];
// Create a random salt
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Create salted password (Careful with the chilli)
$password = hash('sha512', $password.$random_salt);
$username = 'reset';
$email = $_POST['email'];
if ($insert_stmt = $mysqli->prepare("INSERT INTO members1 (username, email, password, salt) VALUES (?, ?, ?, ?)"))
{
$insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
// Execute the prepared query.
$insert_stmt->execute();

$stmt0 = $mysqli -> prepare("update members a set a.password = (select b.password from members1 b where b.email = a.email) where a.email in (select email from members1)");
$stmt0 -> execute();

$stmt1 = $mysqli -> prepare("update members a set a.salt = (select b.salt from members1 b where b.email = a.email) where a.email in (select email from members1)");
$stmt1 -> execute();

$stmt2 = $mysqli -> prepare("truncate table members1");
$stmt2 -> execute();

// header("Location: '..\..\..\?success=1'");
	$srv = $_SERVER['SERVER_NAME'];
	$srvp = $_SERVER['SERVER_PORT'];
	$srvall = "<a href='".$srv.":".$srvp."/index.php' >Login</a>";
printf("<br><br><br><br><br><p style='text-align:center;font-family:verdana;font-size:30px;'>Reset Succesfull</p>");
// printf("<br><br><p style='text-align:center;font-family:verdana;font-size:20px;'>$srvall</p>");
}
else
{
header("Location: '..\..\..\?registrationfailed=1'");
}
?>
