-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgot-password.php
21 lines (18 loc) · 941 Bytes
/
forgot-password.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
include('./classes/DB.php');
include('./classes/Mail.php');
if (isset($_POST['resetpassword'])) {
$cstrong = True;
$token = bin2hex(openssl_random_pseudo_bytes(64, $cstrong));
$email = $_POST['email'];
$user_id = DB::query('SELECT id FROM users WHERE email=:email', array(':email'=>$email))[0]['id'];
DB::query('INSERT INTO password_tokens VALUES (\'\', :token, :user_id)', array(':token'=>sha1($token), ':user_id'=>$user_id));
Mail::sendMail('Forgot Password!', "<a href='http://localhost/tutorials/sn/change-password.php?token=$token'>http://localhost/tutorials/sn/change-password.php?token=$token</a>", $email);
echo 'Email sent!';
}
?>
<h1>Forgot Password</h1>
<form action="forgot-password.php" method="post">
<input type="text" name="email" value="" placeholder="Email ..."><p />
<input type="submit" name="resetpassword" value="Reset Password">
</form>