-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassword-reset.php
executable file
·170 lines (123 loc) · 3.27 KB
/
password-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
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
<?php
// [INCLUDE] //
include('./common/session.php');
include('./connection.php');
// [INIT] //
$email = '';
$v_code = '';
$password = '';
$fetched_email = '';
$fetched_v_code = '';
// Processing form data when form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// [POST-VALUES] //
if (empty($_POST['email'])) { $error = 'No email'; }
else {
$email = trim($_POST['email']);
// [SANITIZE] //
$email = filter_var($email, FILTER_SANITIZE_STRING);
}
// [POST-VALUES] //
if (empty($_POST['v_code'])) { $error = 'No v_code'; }
else {
$v_code = trim($_POST['v_code']);
// [SANITIZE] //
$v_code = filter_var($v_code, FILTER_SANITIZE_STRING);
}
// [POST-VALUES] //
if (empty($_POST['password'])) { $error = 'Please enter password'; }
else {
$password = trim($_POST['password']);
// [SANITIZE] //
$password = filter_var($password, FILTER_SANITIZE_STRING);
}
// Check if email is empty
if (empty($error)) {
// [DATABASE][USER] Check if pvc exist in server //
$stmt = $conn->prepare("
SELECT email, v_code
FROM password_v_codes
WHERE email=?
AND v_code=?
");
// [BIND] parameters for markers //
$stmt->bind_param("ss", $email, $v_code);
// [EXECUTE] query //
$stmt->execute();
// [BIND] result variables //
$stmt->bind_result(
$fetched_email,
$fetched_v_code
);
// [FETCH] value //
$stmt->fetch();
// [CLOSE] //
$stmt->close();
// [VALIDATE] //
if ($fetched_email != '') {
// [DATABASE] prepare and bind //
$stmt = $conn->prepare('
UPDATE users
SET password = ?
WHERE email = ?
');
// [BIND] //
$stmt->bind_param(
'ss',
$password,
$email
);
// [EXECUTE] //
$stmt->execute();
// [CLOSE] //
$stmt->close();
// [DATABASE][DELETE] v_code //
$stmt = $conn->prepare('DELETE FROM password_v_codes WHERE email=?');
// [BIND] //
$stmt->bind_param(
's',
$email
);
// [EXECUTE] //
$stmt->execute();
// [CLOSE] //
$stmt->close();
header('Location: ./login.php');
}
else { $error = 'wrong v_code'; }
}
}
?>
<!-- [HTML] ------------------------------------------------------->
<?php include('header.php'); ?>
<!-- [SPACER] -->
<section class="w3l-about-breadcrumb position-relative text-center">
<div class="breadcrumb-bg breadcrumb-bg-about py-sm-5 py-4"></div>
</section>
<div class="container">
<div class="card card-body mx-auto my-5 shadow" style="max-width: 500px;">
<h3 class="text-center text-dark">Password Recovery</h3>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
<input
type="hidden"
name="email"
id="email"
value="<?php echo $_GET['email']; ?>"
>
<input
type="hidden"
name="v_code"
id="v_code"
value="<?php echo $_GET['v_code']; ?>"
>
<!-- Password -->
<label for="password">Enter new password</label>
<input type="password" name="password" id="password" class="form-control w-100 mb-4">
<!-- [SUBMTI] -->
<button type="submit" class="btn btn-primary w-100">Submit</button>
</form>
</div>
</div>
<!-- Footer -->
<?php include('footer.php'); ?>
<?php include('./common/bottom_script.php'); ?>