-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresetPassword.php
137 lines (115 loc) · 4.71 KB
/
resetPassword.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
<?php
require_once 'connection.php';
if (isset($_POST["reset-password"]))
{
$token = bin2hex(random_bytes(16));
if (@$_GET["email"] == "" || @$_GET["id"] == "")
{
$error_message = "Failed : <br>Don't Modify Url !!";
}
else
{
$email = trim($_GET["email"]);
$id = trim($_GET["id"]);
// Validate e-mail
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
$email = mysqli_real_escape_string($conn, $email);
$id = mysqli_real_escape_string($conn, $id);
$sql = mysqli_query($conn, "SELECT * from user where email='$email' and forgot_password ='$id'"); //Checking Is user Allowed or not
$r = mysqli_num_rows($sql);
if ($r == true)
{
$password = ($_POST["password"]);
$confirmPassword = ($_POST["confirmPassword"]);
$password = mysqli_real_escape_string($conn, $password);
$confirmPassword = mysqli_real_escape_string($conn, $confirmPassword);
if ($password != "" && $confirmPassword != "") // check for null
{
if ($password == $confirmPassword)
{
date_default_timezone_set("Asia/Kolkata");
$login_time = date('Y-m-d H:i:s');
$password = md5($password);
$sql = mysqli_query($conn, "UPDATE user SET pass = '$password',last_login = '$login_time' WHERE email= '$email' AND forgot_password ='$id' ");
$success_message = "Password is updated successfully.";
$sql = mysqli_query($conn, "UPDATE user SET forgot_password = '$token' WHERE email= '$email' "); //After Updating Password changing id to prevent user
//Checking Is user Allowed or not for login
$check = mysqli_query($conn, "SELECT * FROM user WHERE email='$email' AND status = 'allowed' AND email_verified = '1'");
$row = mysqli_num_rows($check);
if ($row == true)
{
$_SESSION['user'] = $email;
echo '<SCRIPT type="text/javascript">
alert("Password Changed successfully.\nNow you are redirecting to Dashboard");
window.location.replace("https://localhost/Faculty-Evaluation-Management-System/user/index.php");
</SCRIPT>';
}else{
$success_message = "Password Changed successfully.<br>
<font color='red'>But, Your account is currenty blocked.<br>Contact Admin</font>";
}
}
else
{
$error_message = "Failed : Password not updated (confirm Password Mismatch)";
}
}
else
{
$error_message = "Failed : Fill all field First";
}
}
else
{
$error_message = "Failed : Your forgot password Link Expired !!";
}
}
else
{
$error_message = "Failed : <br>Invalid Email Id Format !!";
}
}
}
?>
<h2>Reset Password</h2>
<form method="post">
<div class="row">
<div class="col-sm-4"></div>
<?php
if (!empty($success_message))
{
?>
<div class="col-sm-4" style="font-weight: bold;color:green;"><?php
echo $success_message;
?></div>
<?php
}
?>
<?php
if (!empty($error_message))
{
?>
<div class="col-sm-4" style="font-weight: bold;color:red;"><?php
echo $error_message;
?></div>
<?php
}
?>
</div>
<div class="row">
<div class="col-sm-4">Enter Your New Password</div>
<div class="col-sm-5">
<input type="password" name="password" class="form-control"/></div>
</div>
<div class="row">
<div class="col-sm-4">Confirm Your New Password</div>
<div class="col-sm-5">
<input type="password" name="confirmPassword" class="form-control"/></div>
</div>
<div class="row" style="margin-top:10px ;margin-left:150px">
<div class="col-sm-2"></div>
<div class="col-sm-8">
<input type="submit" value="Update Password" name="reset-password" class="btn btn-success"/>
</div>
</div>
</form>