-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_password.php
More file actions
171 lines (140 loc) · 4.66 KB
/
reset_password.php
File metadata and controls
171 lines (140 loc) · 4.66 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
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
<html>
<head>
<script>
function validate_password_reset() {
var currentPassword,newPassword,confirmPassword;
newPassword = document.frmReset.member_password;
confirmPassword = document.frmReset.confirm_password;
if(!newPassword.value) {
newPassword.focus();
alert("New Password cannot be empty");
return false;
}
var len=newPassword.value.length;
if(len<5 || len>25)
{
newPassword.value="";
confirmPassword.value="";
newPassword.focus();
alert("Passwords must be 5 to 25 characters long.");
return false;
}
if(newPassword.value != confirmPassword.value) {
newPassword.value="";
confirmPassword.value="";
newPassword.focus();
alert("Passwords did not match");
return false;
}
return true;
}
</script>
<link href="main1.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
include_once 'dbConnection.php';
$id=$_GET['id'];
$email=$_GET['email'];
if(@$_REQUEST['q']==1 ){
$email=$_REQUEST['email'];
$qmail=$_REQUEST['email'];
$qid=$_REQUEST['id'];
date_default_timezone_set('Asia/Kolkata');
$now = time();
$expires_at= date('Y-m-d H:i:s',$now);
//echo $expires_at;
$r2 = mysqli_query($con,"SELECT * FROM reset WHERE id='$qid' ") or die('Error');
while($row = mysqli_fetch_array($r2)) {
if($expires_at>$row['expires']){
$result3 = mysqli_query($con,"DELETE FROM reset WHERE email='$qmail' ") or die('Error2');
header("location:forgot.php?w='Link expired!'");
exit();
}
}
if(mysqli_num_rows(mysqli_query($con,"SELECT * FROM reset WHERE id='$qid' "))==0){
header("location:forgot.php?w='Link expired!'");
exit();
}
if(isset($_POST["reset-password"])) {
$con = mysqli_connect("localhost", "root", "", "project");
//$email=$_GET['email'];
$email=$_GET['email'];
$qmail=$_GET['email'];
//echo $expires_at;
$r2 = mysqli_query($con,"SELECT * FROM reset WHERE id='$qid' ") or die('Error');
while($row = mysqli_fetch_array($r2)) {
if($expires_at>$row['expires']){
$result3 = mysqli_query($con,"DELETE FROM reset WHERE email='$qmail' ") or die('Error2');
header("location:forgot.php?w='Link expired!'");
exit();
}
}
if(mysqli_num_rows(mysqli_query($con,"SELECT * FROM reset WHERE id='$qid' "))==0){
header("location:forgot.php?w='Link expired!'");
exit();
}
$password=md5($_POST["member_password"]);
//$sql = "UPDATE user SET password = '" . md5($_POST["member_password"]). "' WHERE email = $email";
$result = mysqli_query($con,"UPDATE `user` SET `password`='$password' WHERE email='$email'");
$result1 = mysqli_query($con,"DELETE FROM reset WHERE email='$email' ") or die('Error2');
$success_message = "Password reset successfully.";
// header("location:index.php?w1='$success_message'");
// exit();
}
}
?>
<form name="frmReset" id="frmReset" method="post" action="reset_password.php?q=1&email=<?php echo $_GET['email']; ?>&id=<?php echo $_GET['id']; ?>" onSubmit="return validate_password_reset();">
<?php
if($_GET['q']!=1){
include_once 'dbConnection.php';
$qmail=$_GET['email'];
$qid=$_GET['id'];
date_default_timezone_set('Asia/Kolkata');
$now = time();
$expires_at= date('Y-m-d H:i:s',$now);
$r2 = mysqli_query($con,"SELECT * FROM reset WHERE id='$qid' ") or die('Error');
while($row = mysqli_fetch_array($r2)) {
if($expires_at>$row['expires']){
$result3 = mysqli_query($con,"DELETE FROM reset WHERE email='$qmail' ") or die('Error2');
header("location:forgot.php?w='Link expired!'");
exit();
}
}
$r1 = mysqli_query($con,"SELECT * FROM reset WHERE id='$qid' ") or die('Error');
while($row = mysqli_fetch_array($r1)) {
if($qmail!=$row['email']){
header("location:forgot.php?w='Invalid Link!'");
exit();
}
}
if(mysqli_num_rows(mysqli_query($con,"SELECT * FROM reset WHERE id='$qid' "))==0){
header("location:forgot.php?w='Invalid Link!'");
exit();
}
}
?>
<h1>Reset Password</h1>
<?php if(!empty($success_message)) { ?>
<div class="success_message"><?php echo $success_message; ?><?php echo '<br><br>' ?></div>
<?php } ?>
<div id="validation-message">
<?php if(!empty($error_message)) { ?>
<?php echo $error_message; ?><?php echo '<br><br>' ?>
<?php } ?>
</div>
<div class="field-group">
<div><label for="Password">Password</label></div>
<div>
<input type="password" name="member_password" id="member_password" class="input-field"></div>
</div>
<div class="field-group">
<div><label for="email">Confirm Password</label></div>
<div><input type="password" name="confirm_password" id="confirm_password" class="input-field"></div>
</div>
<div class="field-group">
<br> <div><input type="submit" name="reset-password" id="reset-password" value="Reset Password" class="form-submit-button"></div>
</div>
</form>
</body>
</html>