-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathac_reset_pass.php
More file actions
99 lines (87 loc) · 2.6 KB
/
ac_reset_pass.php
File metadata and controls
99 lines (87 loc) · 2.6 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
<?php
if (isset($_POST['reset'])) {
$selector = $_POST['selector'];
$validator = $_POST['validator'];
$pwd = $_POST['pwd'];
$pwd_re = $_POST['pwd_re'];
if (empty($pwd) || empty($pwd_re)) {
header("location: new_pass.php?error=emptypass");
exit();
}
elseif ($pwd !== $pwd_re){
header("location: new_pass.php?error=pwdnotsame");
exit();
}
$currentDate = date("U");
require 'connectDB.php';
$sql = "SELECT * FROM pwd_reset WHERE pwd_reset_selector=? AND pwd_reset_expires>=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: new_pass.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "ss", $selector, $currentDate);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (!$row = mysqli_fetch_assoc($result)) {
header("location: new_pass.php?error=resubmit");
exit();
}
else{
$tokenBin = hex2bin($validator);
$tokeCheck = password_verify($tokenBin, $row['pwd_reset_token']);
if ($tokeCheck == false) {
header("location: new_pass.php?error=resubmit");
exit();
}
elseif ($tokeCheck == true) {
$tokenEmail = $row['pwd_reset_email'];
$sql = "SELECT * FROM admin WHERE admin_email=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: new_pass.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "s", $tokenEmail);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (!$row = mysqli_fetch_assoc($result)) {
header("location: new_pass.php?error=nouser");
exit();
}
else{
$sql = "UPDATE admin SET admin_pwd=? WHERE admin_email=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: new_pass.php?error=sqlerror");
exit();
}
else{
$newPwdHash = password_hash($pwd, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "ss", $newPwdHash, $tokenEmail);
mysqli_stmt_execute($stmt);
$sql = "DELETE FROM pwd_reset WHERE pwd_reset_email=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: login.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "s", $tokenEmail);
mysqli_stmt_execute($stmt);
header("location: login.php?pwd=pwdUpd");
}
}
}
}
}
}
}
}
else{
header("location: index.php");
exit();
}
?>