<?php

session_start();

require_once "config.php";


$token=$_GET['token'] ?? '';



if(!$token){

die("Invalid reset link");

}





$stmt=$pdo->prepare("

SELECT *

FROM password_resets

WHERE token=?

AND expires_at > NOW()

LIMIT 1

");


$stmt->execute([$token]);


$reset=$stmt->fetch();



if(!$reset){

die("Reset link expired");

}





if($_SERVER["REQUEST_METHOD"]=="POST"){


$password=password_hash(

$_POST['password'],

PASSWORD_DEFAULT

);





$stmt=$pdo->prepare("

UPDATE users

SET password=?

WHERE id=?

");


$stmt->execute([

$password,

$reset['user_id']

]);





$stmt=$pdo->prepare("

DELETE FROM password_resets

WHERE token=?

");


$stmt->execute([$token]);





header("Location: login.php");

exit;



}


?>

<!DOCTYPE html>

<html>

<head>

<title>
Reset Password
</title>


<style>

body{

font-family:Poppins;

background:#f1f5f9;

display:flex;

height:100vh;

justify-content:center;

align-items:center;

}


.box{

background:white;

padding:30px;

border-radius:15px;

width:350px;

}


input,button{

width:100%;

padding:12px;

margin-top:15px;

}


button{

background:#059669;

color:white;

border:0;

}

</style>

</head>


<body>


<div class="box">


<h2>
New Password
</h2>



<form method="POST">


<input

type="password"

name="password"

placeholder="New Password"

required>



<button>

Change Password

</button>


</form>


</div>


</body>

</html>