forked from ivanalayan15/Juanfi-Agent-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_reset.php
More file actions
82 lines (81 loc) · 3.57 KB
/
Copy pathpassword_reset.php
File metadata and controls
82 lines (81 loc) · 3.57 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
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header('location: login.php');
exit;
}
require_once 'config/config.php';
$new_password = $confirm_password = '';
$new_password_err = $confirm_password_err = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty(trim($_POST['new_password']))) {
$new_password_err = 'Please enter the new password.';
} elseif (strlen(trim($_POST['new_password'])) < 6) {
$new_password_err = 'Password must have atleast 6 characters.';
} else {
$new_password = trim($_POST['new_password']);
}
if (empty(trim($_POST['confirm_password']))) {
$confirm_password_err = 'Please confirm the password.';
} else {
$confirm_password = trim($_POST['confirm_password']);
if (empty($new_password_err) && ($new_password != $confirm_password)) {
$confirm_password_err = 'Password did not match.';
}
}
if (empty($new_password_err) && empty($confirm_password_err)) {
$sql = 'UPDATE users SET password = ? WHERE id = ?';
if ($stmt = $mysql_db->prepare($sql)) {
$param_password = password_hash($new_password, PASSWORD_DEFAULT);
$param_id = $_SESSION["id"];
$stmt->bind_param("si", $param_password, $param_id);
if ($stmt->execute()) {
session_destroy();
header("location: login.php");
exit();
} else {
echo "Oops! Something went wrong. Please try again later.";
}
$stmt->close();
}
$mysql_db->close();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Change password Juanfi Agent Manager</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="icon" type="image/x-icon" href="src/kint.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<main>
<section class="container wrapper py-lg-5" style="max-width: 500px;">
<div class="text-center">
<img src="src/logo.png" class="rounded" alt="..." style="width: 150px;">
<h2 class="display-4 pt-5">Change password</h2>
</div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group mb-3<?php echo (!empty($new_password_err)) ? 'has-error' : ''; ?>">
<label>New Password</label>
<input type="password" name="new_password" class="form-control" value="<?php echo $new_password; ?>">
<span class="help-block"><?php echo $new_password_err; ?></span>
</div>
<div class="form-group mb-3 <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control">
<span class="help-block"><?php echo $confirm_password_err; ?></span>
</div>
<div class="form-group d-grid gap-2">
<input type="submit" class="btn btn-block btn-primary" value="Submit">
<a class="btn btn-block btn-link bg-light" href="index.php">Cancel</a>
</div>
</form>
</section>
</main>
</body>
</html>