-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgot_password.php
154 lines (131 loc) · 5.82 KB
/
forgot_password.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
session_start();
$errors = array();
$success = array();
require 'dbconn.php';
?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'admin/vendor/autoload.php';
require_once 'admin/vendor/phpmailer/phpmailer/src/PHPMailer.php';
require_once 'admin/vendor/phpmailer/phpmailer/src/SMTP.php';
require_once 'admin/vendor/phpmailer/phpmailer/src/Exception.php';
if($_SERVER["REQUEST_METHOD"] == "POST"){
$email = $_POST['email'];
$str = '0089773bcghucjdJFGJDNDTEMNVgdhdhjabcdef0987654321';
$token = str_shuffle($str);
// $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]?reset_code=$token";
// var_dump($actual_link);
if($email === "") {
$errors['fields'] = "Email is Required";
}
elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors['email'] = "Email is invalid";
}
else{
$query = mysqli_query($conn, "SELECT * FROM users WHERE email = '$email' LIMIT 1");
if(mysqli_num_rows($query) > 0){
$row = mysqli_fetch_array($query);
$email = $row['email'];
$_SESSION['email'] = $email;
$email = $_SESSION['email'];
$id = $row['id'];
$link="http://localhost/fiverr/oneupmeta/reset_password.php?reset_code=$token";
$to = '$email';
$subject = 'Password Reset link';
// ****HTML Elements for Email Body
$message='
<div>
<p>Hi, you requested a password reset link from oneupmeta website, if you did not initiate this kindly ignore.</p>
<p>Please follow this link to reset your password</p>
<p><a href="'.$link.'">Click to reset</a></p>
</div>
';
try{
$mail = new PHPMailer;
$mail->Host = 'ssl://smtp.gmail.com:465';
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = '[email protected]'; // Gmail address which you want to use as SMTP server
$mail->Password = 'p@ssword123456'; // Gmail address Password
$mail->Port = 465; //587
$mail->SMTPSecure = 'ssl'; //tls
$mail->addAddress($email); // Email address where you want to receive emails (you can use any of your gmail address including the gmail address which you used as SMTP server)
$mail->setFrom('[email protected]', 'Reset Password'); // Gmail address which you used as SMTP server
//$mail->SMTPDebug = 2;
$mail->isHTML(true);
$mail->Subject = 'password reset link';
$mail->Body = $message;
if ($mail->send()){
$success['testt'] = "Password Reset link has been sent your email";
$query = mysqli_query($conn, "UPDATE users SET verification_code = '$token' WHERE email = '$email'");
}else{
$errors['data'] = 'An error occured!';
}
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}else{
$errors['mail'] = 'Email not found';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forgot Password</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body class="bg-white">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4">
<h1 class="text-center text-dark mt-5 mb-4">Forgot Password</h1>
<?php if (count($errors) > 0): ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?php foreach($errors as $error): ?>
<li class="text-danger"><?php echo $error; ?></li>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (count($success) > 0): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?php foreach($success as $succes): ?>
<li class="text-success"><?php echo $succes; ?></li>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="w-100 shadow trans card">
<form method="POST" action="forgot_password.php">
<div class=" form-group mt-4 mr-4 ml-4">
<label for="Username">Enter your email address</label>
<input type="email" class="form-control" name="email" value="" required placeholder="[email protected]">
</div>
<div class="form-group mr-4 ml-4">
<input type="submit" class="btn btn-outline-primary login w-100 mt-2 mb-3" name="submit" value="Get Link">
</div>
</form>
</div>
<div class="trans card w-100 mt-3 shadow">
<p class="text-center mt-2"><a href="signin.php">Go Back</a></p>
</div>
</div>
</div>
</div>
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>