-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.php
68 lines (49 loc) · 1.78 KB
/
reset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
include 'session.php';
if (isset($_POST['reset'])) {
$email = $_POST['email'];
$conn = $pdo->open();
$stmt = $conn->prepare("SELECT *, COUNT(*) AS numrows FROM users WHERE email=:email");
$stmt->execute(['email' => $email]);
$row = $stmt->fetch();
if ($row['numrows'] > 0) {
//generate code
$set = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$code = substr(str_shuffle($set), 0, 15);
try {
$stmt = $conn->prepare("UPDATE users SET reset_code=:code WHERE id=:id");
$stmt->execute(['code' => $code, 'id' => $row['id']]);
try {
$to = "$email"; // Change this email to your //
$subject = "$to";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$From = "[email protected]";
// Create email headers
$message = "Email: ".$email."
Please click the link below to reset your password.
https://bolakaz.unibooks.com.ng/password_reset.php?code=".$code."&user=".$row['id']."
";
$header .= 'From: Bolakaz Enterprise <[email protected]>' . "\r\n";
// if (file_exists($tempfile)) {
// $message = file_get_contents($tempfile);
// $_SESSION['error'] = "sent";
// } else {
// die($_SESSION['error'] = "unable to locate file ");
// }
mail($to, $subject, $message, $header);
$_SESSION['success'] = 'Password reset link sent';
} catch (Exception $e) {
$_SESSION['error'] = 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}
} catch (PDOException $e) {
$_SESSION['error'] = $e->getMessage();
}
} else {
$_SESSION['error'] = 'Email not found';
}
$pdo->close();
} else {
$_SESSION['error'] = 'Input email associated with account';
}
header('location: password_forgot.php');