Newer
Older
Graham Cole
committed
<?php
/***********************************************************************
Graham Cole
committed
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
This file is part of PunBB.
PunBB is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
PunBB is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
************************************************************************/
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
$action = isset($_GET['action']) ? $_GET['action'] : null;
$section = isset($_GET['section']) ? $_GET['section'] : null;
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id < 2)
message($lang_common['Bad request']);
if ($pun_user['g_read_board'] == '0' && ($action != 'change_pass' || !isset($_GET['key'])))
message($lang_common['No view']);
// Load the profile.php/register.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/prof_reg.php';
// Load the profile.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/profile.php';
if ($action == 'change_pass')
{
if (isset($_GET['key']))
{
// If the user is already logged in we shouldn't be here :)
if (!$pun_user['is_guest'])
{
header('Location: index.php');
Graham Cole
committed
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
193
194
195
196
197
198
199
200
}
$key = $_GET['key'];
$result = $db->query('SELECT activate_string, activate_key FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch new password', __FILE__, __LINE__, $db->error());
list($new_password_hash, $new_password_key) = $db->fetch_row($result);
if ($key == '' || $key != $new_password_key)
message($lang_profile['Pass key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
else
{
$db->query('UPDATE '.$db->prefix.'users SET password=\''.$new_password_hash.'\', activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $db->error());
message($lang_profile['Pass updated'], true);
}
}
// Make sure we are allowed to change this users password
if ($pun_user['id'] != $id)
{
if ($pun_user['g_id'] > PUN_MOD) // A regular user trying to change another users password?
message($lang_common['No permission']);
else if ($pun_user['g_id'] == PUN_MOD) // A moderator trying to change a users password?
{
$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang_common['Bad request']);
if ($pun_config['p_mod_edit_users'] == '0' || $pun_config['p_mod_change_passwords'] == '0' || $db->result($result) < PUN_GUEST)
message($lang_common['No permission']);
}
}
if (isset($_POST['form_sent']))
{
if ($pun_user['g_id'] < PUN_GUEST)
confirm_referrer('profile.php');
$old_password = isset($_POST['req_old_password']) ? trim($_POST['req_old_password']) : '';
$new_password1 = trim($_POST['req_new_password1']);
$new_password2 = trim($_POST['req_new_password2']);
if ($new_password1 != $new_password2)
message($lang_prof_reg['Pass not match']);
if (strlen($new_password1) < 4)
message($lang_prof_reg['Pass too short']);
$result = $db->query('SELECT password, save_pass FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch password', __FILE__, __LINE__, $db->error());
list($db_password_hash, $save_pass) = $db->fetch_row($result);
$authorized = false;
if (!empty($db_password_hash))
{
$sha1_in_db = (strlen($db_password_hash) == 40) ? true : false;
$sha1_available = (function_exists('sha1') || function_exists('mhash')) ? true : false;
$old_password_hash = pun_hash($old_password); // This could result in either an SHA-1 or an MD5 hash
if (($sha1_in_db && $sha1_available && $db_password_hash == $old_password_hash) ||
(!$sha1_in_db && $db_password_hash == md5($old_password)) ||
$pun_user['g_id'] < PUN_GUEST)
$authorized = true;
}
if (!$authorized)
message($lang_profile['Wrong pass']);
$new_password_hash = pun_hash($new_password1);
$db->query('UPDATE '.$db->prefix.'users SET password=\''.$new_password_hash.'\' WHERE id='.$id) or error('Unable to update password', __FILE__, __LINE__, $db->error());
if ($pun_user['id'] == $id)
{
$expire = ($save_pass == '1') ? time() + 31536000 : 0;
pun_setcookie($pun_user['id'], $new_password_hash, $expire);
}
redirect('profile.php?section=essentials&id='.$id, $lang_profile['Pass updated redirect']);
}
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Profile'];
$required_fields = array('req_old_password' => $lang_profile['Old pass'], 'req_new_password1' => $lang_profile['New pass'], 'req_new_password2' => $lang_profile['Confirm new pass']);
$focus_element = array('change_pass', (($pun_user['g_id'] > PUN_MOD) ? 'req_old_password' : 'req_new_password1'));
require PUN_ROOT.'header.php';
?>
<div class="blockform">
<h2><span><?php echo $lang_profile['Change pass'] ?></span></h2>
<div class="box">
<form id="change_pass" method="post" action="profile.php?action=change_pass&id=<?php echo $id ?>" onsubmit="return process_form(this)">
<div class="inform">
<input type="hidden" name="form_sent" value="1" />
<fieldset>
<legend><?php echo $lang_profile['Change pass legend'] ?></legend>
<div class="infldset">
<?php if ($pun_user['g_id'] > PUN_MOD): ?> <label><strong><?php echo $lang_profile['Old pass'] ?></strong><br />
<input type="password" name="req_old_password" size="16" maxlength="16" /><br /></label>
<?php endif; ?> <label class="conl"><strong><?php echo $lang_profile['New pass'] ?></strong><br />
<input type="password" name="req_new_password1" size="16" maxlength="16" /><br /></label>
<label class="conl"><strong><?php echo $lang_profile['Confirm new pass'] ?></strong><br />
<input type="password" name="req_new_password2" size="16" maxlength="16" /><br /></label>
<div class="clearb"></div>
</div>
</fieldset>
</div>
<p><input type="submit" name="update" value="<?php echo $lang_common['Submit'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
</form>
</div>
</div>
<?php
require PUN_ROOT.'footer.php';
}
else if ($action == 'change_email')
{
// Make sure we are allowed to change this users e-mail
if ($pun_user['id'] != $id)
{
if ($pun_user['g_id'] > PUN_MOD) // A regular user trying to change another users e-mail?
message($lang_common['No permission']);
else if ($pun_user['g_id'] == PUN_MOD) // A moderator trying to change a users e-mail?
{
$result = $db->query('SELECT group_id FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang_common['Bad request']);
if ($pun_config['p_mod_edit_users'] == '0' || $db->result($result) < PUN_GUEST)
message($lang_common['No permission']);
}
}
if (isset($_GET['key']))
{
$key = $_GET['key'];
$result = $db->query('SELECT activate_string, activate_key FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch activation data', __FILE__, __LINE__, $db->error());
list($new_email, $new_email_key) = $db->fetch_row($result);
if ($key == '' || $key != $new_email_key)
message($lang_profile['E-mail key bad'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.');
else
{
$db->query('UPDATE '.$db->prefix.'users SET email=activate_string, activate_string=NULL, activate_key=NULL WHERE id='.$id) or error('Unable to update e-mail address', __FILE__, __LINE__, $db->error());
Loading
Loading full blame...