forked from ABHRADEEP800/PHP-E_Commerce_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset_pass.php
136 lines (116 loc) · 4.51 KB
/
reset_pass.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
<?php
session_start();
// including database connection
include 'database.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Reset Password</title>
<link rel="icon" type="image/x-icon" href="assets/svg-logo/logo1.svg">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
/>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script
src="https://kit.fontawesome.com/db79afedbd.js"
crossorigin="anonymous"
></script>
<script src="jquery.js"></script>
<script src="main.js"></script>
</head>
<body>
<?php
// including header
include 'header.php';
?>
<!-------------------------------------------------body----------------------------------------------------------->
<div class="container-fluid px-5 my-5">
<div class="row justify-content-center">
<div class="col-xl-6">
<div class="card border-0 rounded-3 shadow-lg overflow-hidden">
<div class="card-body p-0">
<div class="row g-0 d-flex justify-content-center">
<div class="col-sm-10 p-4">
<div class="text-center">
<div class="h3 fw-light">Reset Password</div>
<p class="mb-4 text-muted">Enter Your Email</p>
</div>
<form method="post">
<!-- Email Input -->
<div class="form-floating mb-3">
<input class="form-control" id="emailAddress" type="email" placeholder="Enter Your Email Address" name="email" data-sb-validations="required,email" />
<label for="emailAddress">Email Address</label>
</div>
<!-- Showing Captcha -->
<div>
<img src="captcha.php" alt="captcha" /><br><br>
</div>
<!-- Captcha Input -->
<div class="form-floating mb-3">
<input type="text" name="captcha" id="captcha" class="form-control form-control-lg" placeholder="Enter Captcha Code" />
<label for="captcha">Captcha Code</label>
</div>
<!-- Submit button -->
<div class="d-grid">
<button class="btn btn-primary btn-lg " name="submit" id="submitButton" type="submit">Send Otp</button>
</div>
</form>
<!-- End of contact form -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
// checking if submit button is clicked
if(isset($_POST['submit'])){
// checking if captcha is matched
if($_SESSION['captcha'] == $_POST['captcha']){
// taking form data into variables
$email = $_POST['email'];
$sql = "SELECT * FROM user WHERE user_email = '$email'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$count = mysqli_num_rows($result);
if($count>0){
$otp = rand(100000,999999);
$to = $email;
$_SESSION['otp'] = $otp;
$_SESSION['email'] = $email;
include 'smtp.php';
$mail->addAddress($email); //Add a recipient
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = 'OTP for reset password';
$mail->Body = 'OTP for reset password is '.$otp;
if($mail->send()){
echo "<script>alert('OTP sent to your email')</script>";
echo "<script>window.location.href='cnf_pass.php'</script>";
}
else{
echo "<script>alert('Something went wrong!')</script>";
}
}else{
echo "<script>alert('Email not found!')</script>";
}
}
else{
echo "<script>alert('Captcha is not matched!')</script>";
} // end of if of captcha
} // end of if of submit button
?>
<!------------------------------------------------- footer ----------------------------------------------------------->
<?php
// including footer
include 'footer.php';
?>
</body>
</html>