forked from imsoftware/phpUserAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resetpass.php
192 lines (177 loc) · 5.8 KB
/
resetpass.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
188
189
190
191
192
<?php
require_once('lib/userauth.class.php');
if( ( isset($_GET['do']) && isset($_GET['e']) && isset($_GET['v']) ) || ( isset($_SESSION[SESSION_VARIABLE]) && !isset($_POST['doReset']) ) ) {
if( !isset($_SESSION[SESSION_VARIABLE]) ) {
if( 2 != $user->verifyAccount($_GET['e'], $_GET['v'] ) ) {
echo "Password reset not requested or reset code invalid!";
exit;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
<title>phpUserAuth / Change Password </title>
<link rel="stylesheet" type="text/css" href="inc/form.css">
<script type="text/javascript" src="inc/sha1.js"></script>
<script type="text/javascript" src="inc/validation.js"></script>
</head>
<body>
<form name='resetPasswordForm' method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>' autocomplete="off">
<?php if(isset($_SESSION[SESSION_VARIABLE])) {?>
<div class="inputArea">
<h3>Enter your current password</h3>
<label for="currentpass">Current Password</label>
<input type="password" name="currentpass" id="currentpass" tabindex="1" />
<span class="formError" id="currentpassError"></span>
</div>
<div class="inputArea">
<label for="email">New email address</label>
<input type="text" name="email" id="email" tabindex="1" />
<span class="formError" id="emailError"></span>
</div>
<?php
}
?>
<div class="inputArea">
<h3>Change Password</h3>
<label for="pass">Password</label>
<input type="password" name="pass" id="pass" tabindex="2" />
<span class="formError" id="passError"></span>
<label for="repass">Confirm Password</label>
<input type="password" name="repass" id="repass" tabindex="3" />
<span class="formError" id="repassError"></span>
<?php
if(isset($_GET['e']))
echo "<input type='hidden' name='e' value='".$_GET['e']."' />";
?>
<script type="text/javascript">
document.write('<input type="hidden" name="hashed" value="1" />');
</script>
<br /><input type="submit" name="doReset" onclick="return processForm();" value="Update" />
<a href="#" onclick="history.go(-1);">Cancel</a>
</div>
</form>
<script type="text/javascript">
function processForm() {
span = document.resetPasswordForm.getElementsByTagName("span");
for(i=0;i<span.length;i++)
span[i].innerHTML = '';
pass = document.getElementById('pass').value;
repass = document.getElementById('repass').value;
<?php
if(isset($_SESSION[SESSION_VARIABLE])) {
?>
currentpass = document.getElementById('currentpass').value;
email = document.getElementById('email').value;
if(email == '' && pass == '') {
return false;
}
else {
if(!password(currentpass, 'currentpassError')) {
return false;
}
if(email != '') {
if(!mail(email))
return false;
}
if(pass != '') {
if( password(pass, 'passError') && password(repass, 'repassError') && checkpass(pass, repass) ) {
document.getElementById('pass').value = hex_sha1(pass);
document.getElementById('repass').value = hex_sha1(repass);
}
else {
return false;
}
}
document.getElementById('currentpass').value = hex_sha1(currentpass);
return true;
}
<?php
}
else {
?>
if( password(pass, 'passError') && password(repass,'repassError') && checkpass(pass, repass) ) {
document.getElementById('pass').value = hex_sha1(pass);
document.getElementById('repass').value = hex_sha1(repass);
return true;
}
return false;
<?php
}
?>
return true;
}
</script>
</body>
</html>
<?php
exit;
}
else if( isset($_POST['doReset']) ) {
// Resetting password through email
if(isset($_POST['e'])) {
if($_POST['pass'] !== $_POST['repass']) {
echo "Passwords do not match. Error changing password!";
exit;
}
// If the password has not been sent hashed by javascript, find the sha1 hash now
if(!isset($_POST['hashed']) || $_POST['hashed'] != 1) {
$_POST['pass'] = sha1($_POST['pass']);
}
if($user->changePassword($_POST['pass'], $_POST['e'])) {
echo "Password changed successfully! Please login with your new password";
exit;
}
else {
die("Error changing password!");
}
}
// Changing password after login
else if( isset($_SESSION[SESSION_VARIABLE]) && isset($_POST['currentpass']) ) {
$user->is();
// If the password has not been sent hashed by javascript, find the sha1 hash now
if(!isset($_POST['hashed']) || $_POST['hashed'] != 1)
$_POST['currentpass'] = sha1($_POST['currentpass']);
// Check if the current password entered is valid
$email = $user->checkExisting('pass', $_POST['currentpass']);
// If the user is valid
if($email) {
// If the email needs to be updated
if(!empty($_POST['email'])) {
if( $email == $_POST['email'] ) {
echo "New email id is the same as old. Nothing to update";
}
if ( !$user->checkExisting('email', $_POST['email']) ) {
if( $user->updateProperty('email', $_POST['email'], $_SESSION[SESSION_VARIABLE]["id"]) ) {
echo "Email updated successfully!";
}
else {
echo "Nothing to update";
}
}
else {
echo "Email address already exists! Not updating";
}
}
// If the pass needs to be updated
if( !empty($_POST['pass']) && !empty($_POST['repass']) ) {
if($_POST['pass'] !== $_POST['repass']) {
echo "Passwords do not match. Error changing password!";
exit;
}
if(!isset($_POST['hashed']) || $_POST['hashed'] != 1)
$_POST['pass'] = sha1($_POST['pass']);
if($user->changePassword( $_POST['pass'], $email) ) {
$user->logout("Password changed successfully! You have been logged out for security reasons",true);
}
else {
die("Error changing password!");
}
}
}
}
}
?>