-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot-password.php
More file actions
140 lines (115 loc) · 5.2 KB
/
forgot-password.php
File metadata and controls
140 lines (115 loc) · 5.2 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
session_start();
if (isset($_SESSION['SESSION_EMAIL'])) {
header("Location: welcome.php");
die();
}
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
include 'config.php';
$msg = "";
if (isset($_POST['submit'])) {
$email = mysqli_real_escape_string($connect, $_POST['email']);
$code = mysqli_real_escape_string($connect, md5(rand()));
if (mysqli_num_rows(mysqli_query($connect, "SELECT * FROM users WHERE email='{$email}'")) > 0) {
$query = mysqli_query($connect, "UPDATE users SET code='{$code}' WHERE email='{$email}'");
if ($query) {
echo "<div style='display: none;'>";
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'nayeem3004@gmail.com'; //SMTP username
$mail->Password = '123456789'; //SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = 465; //TCP port to connectect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom('nayeem3004@gmail.com');
$mail->addAddress($email);
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'no reply';
$mail->Body = 'Here is the verification link <b><a href="http://localhost/MFA2/change-password.php?reset='.$code.'">http://localhost/MFA2/change-password.php?reset='.$code.'</a></b>';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
echo "</div>";
$msg = "<div class='alert alert-info'>We've send a verification link on your email address.</div>";
}
} else {
$msg = "<div class='alert alert-danger'>$email - This email address do not found.</div>";
}
}
?>
<!DOCTYPE html>
<html lang="zxx">
<head>
<title>Login Form </title>
<!-- Meta tag Keywords -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8" />
<meta name="keywords"
content="Login Form" />
<!-- //Meta tag Keywords -->
<link href="//fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet">
<!--/Style-CSS -->
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<!--//Style-CSS -->
<script src="https://kit.fontawesome.com/af562a2a63.js" crossorigin="anonymous"></script>
</head>
<body>
<!-- form section start -->
<section class="w3l-mockup-form">
<div class="container">
<!-- /form -->
<div class="workinghny-form-grid">
<div class="main-mockup">
<div class="alert-close">
<span class="fa fa-close"></span>
</div>
<div class="w3l_form align-self">
<div class="left_grid_info">
<img src="images/image3.svg" alt="">
</div>
</div>
<div class="content-wthree">
<h2>Forgot Password</h2>
<p>please enter new password</p>
<?php echo $msg; ?>
<form action="" method="post">
<input type="email" class="email" name="email" placeholder="Enter Your Email" required>
<button name="submit" class="btn" type="submit">Send Reset Link</button>
</form>
<div class="social-icons">
<p>Back to! <a href="index.php">Login</a>.</p>
</div>
</div>
</div>
</div>
<!-- //form -->
</div>
</section>
<!-- //form section start -->
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function (c) {
$('.alert-close').on('click', function (c) {
$('.main-mockup').fadeOut('slow', function (c) {
$('.main-mockup').remove();
});
});
});
</script>
</body>
</html>