-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_password.php
More file actions
92 lines (83 loc) · 3.03 KB
/
Copy pathreset_password.php
File metadata and controls
92 lines (83 loc) · 3.03 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
<?php
session_start();
require_once 'mysql.php';
require_once 'functions.php';
if (isset($_POST['submit'])) {
$password = $_POST['password'] ?? '';
$token = $_POST['token'] ?? '';
if ($password === '' || $token === '') {
print('Password is required');
exit();
}
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = $connection->prepare('UPDATE users SET password_hash = :password WHERE reset_token = :token');
$stmt->execute([
':password' => $hashed_password,
':token' => $token,
]);
} catch (PDOException $e) {
header('Location: msg.php?msg=Failed to update password&type=error&goto=reset_password.php');
exit();
}
if ($stmt->rowCount() > 0) {
try {
$stmt = $connection->prepare('UPDATE users SET reset_token = NULL WHERE reset_token = :token');
$stmt->execute([':token' => $token]);
} catch (PDOException $e) {
// Ignore cleanup failure; main password update already succeeded.
}
header('Location: msg.php?msg=Password updated successfully&type=success&goto=login.php');
exit();
}
header('Location: msg.php?msg=Failed to update password&type=error&goto=reset_password.php');
exit();
}
$token = $_GET['token'] ?? '';
if ($token !== '') {
try {
$stmt = $connection->prepare(
'SELECT id FROM users WHERE reset_token = :token AND reset_token IS NOT NULL LIMIT 1'
);
$stmt->execute([':token' => $token]);
} catch (PDOException $e) {
header('Location: msg.php?msg=Invalid token&type=error&goto=reset_password.php');
exit();
}
if ($stmt->rowCount() === 0) {
header('Location: msg.php?msg=Invalid token&type=error&goto=reset_password.php');
exit();
}
} else {
header('Location: msg.php?msg=Token required&type=error&goto=forget_password.php');
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Password</title>
<link rel="stylesheet" href="//static.owaspzero-x.ir/styles.css">
</head>
<body>
<div class="home-link">
<a class="btn" href="/index.php"><span class="icon">⌂</span>Home</a>
</div>
<div class="card">
<h1>Reset Password</h1>
<form method="POST" action="/reset_password.php" accept-charset="UTF-8" autocomplete="on" novalidate>
<div class="form-group">
<label for="password">New Password</label>
<input id="password" name="password" type="password"
placeholder="********" required minlength="1" maxlength="120" />
<input type="hidden" name="token" value="<?php echo htmlspecialchars($token, ENT_QUOTES, 'UTF-8'); ?>" />
</div>
<div class="form-group">
<button type="submit" name="submit">Reset Password</button>
</div>
</form>
</div>
</body>
</html>