1 |
4
|
ryan
|
<?php
|
2 |
|
|
|
3 |
17
|
stefan
|
// $Id$
|
4 |
4
|
ryan
|
|
5 |
|
|
/*
|
6 |
|
|
|
7 |
|
|
Website Baker Project <http://www.websitebaker.org/>
|
8 |
399
|
Ruebenwurz
|
Copyright (C) 2004-2007, Ryan Djurovich
|
9 |
4
|
ryan
|
|
10 |
|
|
Website Baker is free software; you can redistribute it and/or modify
|
11 |
|
|
it under the terms of the GNU General Public License as published by
|
12 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
(at your option) any later version.
|
14 |
|
|
|
15 |
|
|
Website Baker is distributed in the hope that it will be useful,
|
16 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
GNU General Public License for more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License
|
21 |
|
|
along with Website Baker; if not, write to the Free Software
|
22 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
if(!defined('WB_URL')) {
|
27 |
17
|
stefan
|
header('Location: ../pages/index.php');
|
28 |
286
|
stefan
|
exit(0);
|
29 |
4
|
ryan
|
}
|
30 |
|
|
|
31 |
|
|
// Create new database object
|
32 |
|
|
$database = new database();
|
33 |
|
|
|
34 |
|
|
// Check if the user has already submitted the form, otherwise show it
|
35 |
|
|
if(isset($_POST['email']) AND $_POST['email'] != "") {
|
36 |
|
|
|
37 |
|
|
$email = $_POST['email'];
|
38 |
|
|
|
39 |
|
|
// Check if the email exists in the database
|
40 |
293
|
stefan
|
$query = "SELECT user_id,username,display_name,email,last_reset,password FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'";
|
41 |
4
|
ryan
|
$results = $database->query($query);
|
42 |
|
|
if($results->numRows() > 0) {
|
43 |
322
|
stefan
|
|
44 |
|
|
// Get the id, username, email, and last_reset from the above db query
|
45 |
4
|
ryan
|
$results_array = $results->fetchRow();
|
46 |
|
|
|
47 |
226
|
ryan
|
// Check if the password has been reset in the last 2 hours
|
48 |
|
|
$last_reset = $results_array['last_reset'];
|
49 |
|
|
$time_diff = mktime()-$last_reset; // Time since last reset in seconds
|
50 |
|
|
$time_diff = $time_diff/60/60; // Time since last reset in hours
|
51 |
|
|
if($time_diff < 2) {
|
52 |
|
|
|
53 |
|
|
// Tell the user that their password cannot be reset more than once per hour
|
54 |
|
|
$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
|
55 |
|
|
|
56 |
|
|
} else {
|
57 |
4
|
ryan
|
|
58 |
322
|
stefan
|
$old_pass = $results_array['password'];
|
59 |
|
|
|
60 |
226
|
ryan
|
// Generate a random password then update the database with it
|
61 |
|
|
$new_pass = '';
|
62 |
|
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
63 |
|
|
srand((double)microtime()*1000000);
|
64 |
|
|
$i = 0;
|
65 |
|
|
while ($i <= 7) {
|
66 |
|
|
$num = rand() % 33;
|
67 |
|
|
$tmp = substr($salt, $num, 1);
|
68 |
|
|
$new_pass = $new_pass . $tmp;
|
69 |
|
|
$i++;
|
70 |
|
|
}
|
71 |
322
|
stefan
|
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".mktime()."' WHERE user_id = '".$results_array['user_id']."'");
|
72 |
226
|
ryan
|
|
73 |
|
|
if($database->is_error()) {
|
74 |
|
|
// Error updating database
|
75 |
|
|
$message = $database->get_error();
|
76 |
|
|
} else {
|
77 |
|
|
// Setup email to send
|
78 |
|
|
$mail_subject = 'Your login details...';
|
79 |
|
|
$mail_to = $email;
|
80 |
|
|
$mail_message = ''.
|
81 |
4
|
ryan
|
'Hello '.$results_array["display_name"].',
|
82 |
|
|
|
83 |
|
|
Your '.WEBSITE_TITLE.' administration login details are:
|
84 |
|
|
Username: '.$results_array["username"].'
|
85 |
|
|
Password: '.$new_pass.'
|
86 |
|
|
|
87 |
|
|
Your password has been reset to the one above.
|
88 |
|
|
This means that your old password will no longer work.
|
89 |
|
|
|
90 |
352
|
ryan
|
If you have received this message in error, please delete it immediately.';
|
91 |
226
|
ryan
|
// Try sending the email
|
92 |
344
|
stefan
|
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
|
93 |
226
|
ryan
|
$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET'];
|
94 |
|
|
$display_form = false;
|
95 |
|
|
} else {
|
96 |
322
|
stefan
|
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'");
|
97 |
226
|
ryan
|
$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'];
|
98 |
|
|
}
|
99 |
4
|
ryan
|
}
|
100 |
322
|
stefan
|
|
101 |
|
|
}
|
102 |
|
|
|
103 |
4
|
ryan
|
} else {
|
104 |
|
|
// Email doesn't exist, so tell the user
|
105 |
|
|
$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
} else {
|
109 |
|
|
$email = '';
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
if(!isset($message)) {
|
113 |
|
|
$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
|
114 |
|
|
$message_color = '000000';
|
115 |
|
|
} else {
|
116 |
|
|
$message_color = 'FF0000';
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
?>
|
120 |
|
|
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
|
121 |
|
|
|
122 |
|
|
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot'.PAGE_EXTENSION; ?>" method="post">
|
123 |
|
|
<input type="hidden" name="url" value="{URL}" />
|
124 |
|
|
<table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
|
125 |
|
|
<tr>
|
126 |
|
|
<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2">
|
127 |
|
|
<?php echo $message; ?>
|
128 |
|
|
</td>
|
129 |
|
|
</tr>
|
130 |
|
|
<?php if(!isset($display_form) OR $display_form != false) { ?>
|
131 |
|
|
<tr>
|
132 |
|
|
<td height="10" colspan="2"></td>
|
133 |
|
|
</tr>
|
134 |
|
|
<tr>
|
135 |
|
|
<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td>
|
136 |
352
|
ryan
|
<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td>
|
137 |
4
|
ryan
|
</tr>
|
138 |
|
|
<tr height="30">
|
139 |
|
|
<td> </td>
|
140 |
|
|
<td><input type="submit" name="submit" value="<?php echo $TEXT['SEND_DETAILS']; ?>" style="width: 180px; font-size: 10px; color: #003366; border: 1px solid #336699; background-color: #DDDDDD; padding: 3px; text-transform: uppercase;"></td>
|
141 |
|
|
</tr>
|
142 |
|
|
<tr style="display: {DISPLAY_FORM}">
|
143 |
|
|
<td height="10" colspan="2"></td>
|
144 |
|
|
</tr>
|
145 |
|
|
<?php } ?>
|
146 |
|
|
</table>
|
147 |
239
|
stefan
|
</form>
|