-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseraccountreset.php
187 lines (157 loc) · 7.03 KB
/
useraccountreset.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
require "assets/db.php";
require "assets/varnames.php";
require 'assets/sharedComponents.php';
$components = new SharedComponents();
include 'includes/header.php';
include 'includes/navbar.php';
?>
<?php
if(isset($_GET['code']) && isset($_GET['userid']))
{
$_SESSION["resetcode"] = $_GET['code'];
$_SESSION["resetaccountid"] = $_GET['userid'];
}
session_start();
// Define variables and initialize with empty values
$password = $password_err = $confrimpassword_err ="";
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(isset($_SESSION['resetcode']) && isset($_SESSION['resetaccountid']))
{
// Check if all password is empty
if (empty(trim($_POST["password"]))) {
$password_err = "Enter your Password.";
}
else if (empty(trim($_POST["confrimpassword"]))) {
$confrimpassword_err = "Confrim your Password.";
}
else if ($_POST["confrimpassword"] != $_POST["password"]){
$confrimpassword_err = "Passwords does not Match.";
}
else {
$password = trim($_POST["password"]);
}
// Validate credentials
if (empty($password_err) && empty($confrimpassword_err)) {
$userid = $components->unprotect($_SESSION['resetaccountid']);
// Prepare a select statement
$sql = "SELECT * FROM users WHERE id = :id";
if ($stmt = $pdo->prepare($sql))
{
$stmt->bindParam(":id", $userid, PDO::PARAM_STR);
if ($stmt->execute())
{
if ($stmt->rowCount() == 1)
{
if ($row = $stmt->fetch())
{
$username = $row["username"];
$usercode = $row["code"];
if ($usercode == $_SESSION['resetcode'])
{
$hashpassword = password_hash($password, PASSWORD_DEFAULT);
//update user password
$bsql = "UPDATE users SET password=:password WHERE id=:id";
$stmt= $pdo->prepare($bsql);
$stmt->execute(['password' => $hashpassword, 'id' => $userid]);
if ($stmt->rowCount()) {
unset($_SESSION['resetcode']);
unset($_SESSION['resetaccountid']);
if(isset($_SESSION["main_err"]))
{
unset($_SESSION["main_err"]);
}
header("Location: login.php?newadmsg=active");
exit;
}
else
{
$_SESSION["main_err"] = "Error Updating Account, contact site administrator";
}
}
else
{
$_SESSION["main_err"] = "User codes Doesn't Match, click the last sent link from us in your email.";
}
}
}
else
{
$_SESSION["main_err"] = "No account found with gotten User Identification.";
}
}
else
{
$_SESSION["main_err"] = "Oops! Something went wrong. Please try again later.";
}
unset($stmt);
}
}
// Close connection
unset($pdo);
}
else
{
$_SESSION["main_err"] = "No account found with gotten User Identification.";
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Meta -->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- favicon -->
<link rel="icon" sizes="16x16" href="assets/img/favicon.png">
<!-- Title -->
<title> Admin | Login </title>
<!-- CSS Plugins -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/owl.carousel.css">
<link rel="stylesheet" href="assets/css/line-awesome.min.css">
<link rel="stylesheet" href="assets/css/fontawesome.css">
<!-- main style -->
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/custom.css">
<?php require "includes/metatags.php"; ?>
</head>
<body>
<!--Login-->
<section class="container">
<br>
<div class="section-heading">
<div class="row">
<div class="col-lg-6 col-md-8 m-auto">
<div class="login-content">
<h4> Password Reset</h4>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" class="sign-form widget-form " method="POST">
<p class="text-center m-2 text-danger">
<?= (!empty($_SESSION["main_err"])) ? $_SESSION["main_err"] : ''; unset($_SESSION["main_err"]) ?>
</p>
<div class="form-group">
<input type="password" name="password" class="form-control <?= (!empty($password_err)) ? 'is-invalid' : ''; ?>" placeholder="Password*">
<span class="invalid-feedback"><?= $password_err; ?></span>
</div>
<div class="form-group">
<input type="password" class="form-control <?= (!empty($confrimpassword_err)) ? 'is-invalid' : ''; ?>" placeholder="Confrim Password*" name="confrimpassword" value="">
<span class="invalid-feedback"><?= $confrimpassword_err; ?></span>
</div>
<div class="form-group">
<button type="submit" class="btn-custom">Submit</button>
</div>
<p class="form-group text-center">Don't have an account? <a href="adminsignup.php" class="btn-link">Create One</a> </p>
</form>
</div>
</div>
</div>
</div>
</section>
<br>
<?php
include 'includes/footer.php';
include 'includes/scripts.php';
?>