-
Notifications
You must be signed in to change notification settings - Fork 0
/
changepassotp.php
173 lines (158 loc) · 5.35 KB
/
changepassotp.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
require_once "config.php";
$email = "";
$email_err = "";
if ($_SERVER['REQUEST_METHOD'] == "POST"){
// Check if email is empty
if(empty(trim($_POST["email"]))){
$email_err = "email cannot be blank";
echo "<p class='echocss'>Email address cannot be blank.</p>";
}
else{
$sql = "SELECT id FROM changepass WHERE email = ?";
$stmt = mysqli_prepare($conn, $sql);
if($stmt)
{
mysqli_stmt_bind_param($stmt, "s", $param_email);
// Set the value of param email
$param_email = trim($_POST['email']);
$email = trim($_POST['email']);
}
}
$otp = rand(100000,999999);
// If there were no errors, go ahead and insert into the database
if(empty($email_err))
{
$sql = "INSERT INTO changepass (email,otp) VALUES (?, ?)";
$stmt = mysqli_prepare($conn, $sql);
if ($stmt)
{
mysqli_stmt_bind_param($stmt, "ss",$param_email,$param_otp);
// Set these parameters
$param_email = $email;
$param_otp = $otp;
// Try to execute the query
if (mysqli_stmt_execute($stmt))
{
$to_email = $email;
$subject = "Email Verification";
$body = "Hi, your otp to change your account password is " . $otp;
$headers = "From: [email protected]";
if (mail($to_email, $subject, $body, $headers)) {
header("location: otppasschange.php");
}
}
else{
echo "Something went wrong... cannot redirect!";
}
}
mysqli_stmt_close($stmt);
}
mysqli_close($conn);
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
body{
background-image: url("img/SiteBg.jpg");
background-size: cover:
}
form{
background-color: #E5E8E8;
margin-left: 24em;
margin-right: 4em;
margin-top: 6em;
padding: 30px;
box-shadow: 10px 10px 8px 10px #888888;
}
.echocss{
margin-left: 50em;
margin-right: 31em;
margin-top: 5px;
position: absolute;
color: red;
}
.home{
position: absolute;
margin-top: -80px;
margin-left: 10px;
}
/*Styles for small screens*/
@media screen and (max-width: 700px) {
form{
background-color: #E5E8E8;
margin-left: -2em;
margin-right: -4em;
box-shadow: 10px 10px 8px 10px #888888;
}
.echocss{
margin-left: 12em;
margin-right: 7em;
margin-top: 37px;
position: absolute;
color: red;
}
}
/* On screens that are less than 400px, display the bar vertically, instead of horizontally */
@media screen and (max-width: 400px) {
form{
background-color: #E5E8E8;
margin-left: -2em;
margin-right: -4em;
box-shadow: 10px 10px 8px 10px #888888;
}
.echocss{
margin-left: 12em;
margin-right: 7em;
margin-top: 37px;
position: absolute;
color: red;
}
}
@media screen and (max-width: 1156px) {
form{
background-color: #E5E8E8;
margin-left: -2em;
margin-right: -4em;
box-shadow: 10px 10px 8px 10px #888888;
}
.echocss{
margin-left: 12em;
margin-right: 3em;
margin-top: 37px;
position: absolute;
color: red;
}
}
</style>
<title>Change Password</title>
<link rel="shortcut icon" type="image/x-icon" href="img/NLJ.png">
</head>
<body>
<div class="home">
<a href="index.php"><img src="https://img.icons8.com/material-rounded/48/000000/home.png"/></a>
</div>
<div class="container mt-4">
<form action="" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="text" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<button type="submit" class="btn btn-primary">Send OTP</button>
<p style="text-align: center;">New user?<br>Create Account <a href="register.php">Sign Up</a></p>
</form>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>