-
Notifications
You must be signed in to change notification settings - Fork 1
/
reset.php
157 lines (100 loc) · 6.1 KB
/
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
<?php require_once('includes/header.php'); ?>
<!-- Navigation -->
<?php require_once('includes/nav.php'); ?>
<?php
if(!isset($_GET['email']) || !isset($_GET['token']) || isset($_SESSION['user_role'])) {
header("Location: /php-cms/");
exit();
}
$email = $_GET['email'];
$token = $_GET['token'];
$user_info_stmt = mysqli_prepare($connection, "SELECT username, email, token FROM tblusers WHERE token = ? AND email = ?");
checkPreparedStatement($user_info_stmt);
mysqli_stmt_bind_param($user_info_stmt, "ss", $token, $email);
mysqli_stmt_execute($user_info_stmt);
mysqli_stmt_bind_result($user_info_stmt, $username, $email, $token);
mysqli_stmt_fetch($user_info_stmt);
mysqli_stmt_close($user_info_stmt);
if(isset($_POST['password']) && isset($_POST['confirm_password'])) {
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
if(strcmp($password, $confirm_password) == 0) {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$update_password_stmt = mysqli_prepare($connection, "UPDATE tblusers SET password = ?, token = '' WHERE email = ?");
checkPreparedStatement($update_password_stmt);
mysqli_stmt_bind_param($update_password_stmt, "ss", $hashed_password, $email);
mysqli_stmt_execute($update_password_stmt);
$message = "Success";
} else {
$message = "Not Match";
}
}
?>
<!-- Page Content -->
<div class="container">
<div class="form-gap"></div>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-body">
<div class="text-center">
<h3><i class="fa fa-lock fa-4x"></i></h3>
<h2 class="text-center">Reset Password?</h2>
<p>You can reset your password here.</p>
<?php
$show_form = true;
if(!isset($email)) {
echo "<div class='alert alert-danger alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden=true'>×</span></button>
The email or token is not valid</div>";
$show_form = false;
} else {
if(isset($message)) {
if($message == "Success") {
echo "<div class='alert alert-success alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden=true'>×</span></button>
Your password have been reset. You can <a href='/php-cms/login'>login</a> now.</div>";
$show_form = false;
} elseif($message == "Not Match") {
echo "<div class='alert alert-danger alert-dismissible' role='alert'>
<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden=true'>×</span></button>
The passwords does not match!</div>";
$show_form = true;
}
}
if($show_form) {
?>
<div class="panel-body">
<form id="register-form" role="form" autocomplete="off" class="form" method="post">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock color-blue"></i></span>
<input id="password" name="password" placeholder="New Password" class="form-control" type="password" required>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-ok color-blue"></i></span>
<input id="confirm_password" name="confirm_password" placeholder="Confirm Password" class="form-control" type="password" required>
</div>
</div>
<div class="form-group">
<input name="recover-submit" class="btn btn-lg btn-primary btn-block" value="Reset Password" type="submit">
</div>
<input type="hidden" class="hide" name="token" id="token" value="">
</form>
</div><!-- Body-->
<?php
}
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<hr>
<?php require_once('includes/footer.php');?>
</div> <!-- /.container -->