Stworzyłem taki scrypt:
Po rozpoczęciu procesu resetu hasła w innym pliku generowany jest token z datą i godziną w postaci timestamp, zapisuje go w bazie danych a do użytkownika leci link do resetu hasła. Po kliknięciu w link poniższy kod sprawdza ważność tokena i wykonuje kod w zależności czy link jest ważny czy nie.
if(isset($_GET['username']) && !empty($_GET['username']) AND isset($_GET['hash']) && !empty($_GET['hash']) AND isset($_GET['token']) && !empty($_GET['token'])) {
$username = mysqli_real_escape_string($connect, $_GET['username']);
$hash = mysqli_real_escape_string($connect, $_GET['hash']);
$token = mysqli_real_escape_string($connect, $_GET['token']);
//check if token is still valid
$sql = "SELECT * FROM passres WHERE u_token='$token'";
$result = mysqli_query($connect, $sql);
$dbTimestamp = $result->fetch_assoc();
$resetTime = $dbTimestamp['u_resetTime'];
$date = date_create();
$currenTime = date_timestamp_get($date);
if ($currenTime - $resetTime > 3600) {
echo $_SESSION['msg_error'] = "Sorry, reset link already expired. Please try again.";
header('Location: index.html');
exit();
} else {
Scrypt działa i spełnia swoja funkcje.