Revision 1189
Added by Dietmar over 14 years ago
forgot_form.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, Ryan Djurovich |
|
9 |
|
|
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 |
header('Location: ../pages/index.php'); |
|
28 |
exit(0); |
|
29 |
} |
|
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']) && $_POST['email'] != "" && |
|
36 |
eregi("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $_POST['email'])) { |
|
37 |
$email = strip_tags($_POST['email']); |
|
38 |
|
|
39 |
// Check if the email exists in the database |
|
40 |
$query = "SELECT user_id,username,display_name,email,last_reset,password FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'"; |
|
41 |
$results = $database->query($query); |
|
42 |
if($results->numRows() > 0) { |
|
43 |
|
|
44 |
// Get the id, username, email, and last_reset from the above db query |
|
45 |
$results_array = $results->fetchRow(); |
|
46 |
|
|
47 |
// Check if the password has been reset in the last 2 hours |
|
48 |
$last_reset = $results_array['last_reset']; |
|
49 |
$time_diff = time()-$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 |
|
|
58 |
$old_pass = $results_array['password']; |
|
59 |
|
|
60 |
// 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 |
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'"); |
|
72 |
|
|
73 |
if($database->is_error()) { |
|
74 |
// Error updating database |
|
75 |
$message = $database->get_error(); |
|
76 |
} else { |
|
77 |
// Setup email to send |
|
78 |
$mail_to = $email; |
|
79 |
$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO']; |
|
80 |
|
|
81 |
// Replace placeholders from language variable with values |
|
82 |
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}'); |
|
83 |
$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass); |
|
84 |
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']); |
|
85 |
|
|
86 |
// Try sending the email |
|
87 |
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { |
|
88 |
$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET']; |
|
89 |
$display_form = false; |
|
90 |
} else { |
|
91 |
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'"); |
|
92 |
$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL']; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
} else { |
|
99 |
// Email doesn't exist, so tell the user |
|
100 |
$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND']; |
|
101 |
} |
|
102 |
|
|
103 |
} else { |
|
104 |
$email = ''; |
|
105 |
} |
|
106 |
|
|
107 |
if(!isset($message)) { |
|
108 |
$message = $MESSAGE['FORGOT_PASS']['NO_DATA']; |
|
109 |
$message_color = '000000'; |
|
110 |
} else { |
|
111 |
$message_color = 'FF0000'; |
|
112 |
} |
|
113 |
|
|
114 |
?> |
|
115 |
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1> |
|
116 |
|
|
117 |
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot.php'; ?>" method="post"> |
|
118 |
<input type="hidden" name="url" value="{URL}" /> |
|
119 |
<table cellpadding="5" cellspacing="0" border="0" align="center" width="500"> |
|
120 |
<tr> |
|
121 |
<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2"> |
|
122 |
<?php echo $message; ?> |
|
123 |
</td> |
|
124 |
</tr> |
|
125 |
<?php if(!isset($display_form) OR $display_form != false) { ?> |
|
126 |
<tr> |
|
127 |
<td height="10" colspan="2"></td> |
|
128 |
</tr> |
|
129 |
<tr> |
|
130 |
<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td> |
|
131 |
<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td> |
|
132 |
</tr> |
|
133 |
<tr height="30"> |
|
134 |
<td> </td> |
|
135 |
<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> |
|
136 |
</tr> |
|
137 |
<tr style="display: {DISPLAY_FORM}"> |
|
138 |
<td height="10" colspan="2"></td> |
|
139 |
</tr> |
|
140 |
<?php } ?> |
|
141 |
</table> |
|
1 |
<?php |
|
2 |
|
|
3 |
// $Id$ |
|
4 |
|
|
5 |
/* |
|
6 |
|
|
7 |
Website Baker Project <http://www.websitebaker.org/> |
|
8 |
Copyright (C) 2004-2009, Ryan Djurovich |
|
9 |
|
|
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 |
header('Location: ../pages/index.php'); |
|
28 |
exit(0); |
|
29 |
} |
|
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']) && $_POST['email'] != "" && |
|
36 |
preg_match("/([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}/i", $_POST['email'])) { |
|
37 |
$email = strip_tags($_POST['email']); |
|
38 |
|
|
39 |
// Check if the email exists in the database |
|
40 |
$query = "SELECT user_id,username,display_name,email,last_reset,password FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'"; |
|
41 |
$results = $database->query($query); |
|
42 |
if($results->numRows() > 0) { |
|
43 |
|
|
44 |
// Get the id, username, email, and last_reset from the above db query |
|
45 |
$results_array = $results->fetchRow(); |
|
46 |
|
|
47 |
// Check if the password has been reset in the last 2 hours |
|
48 |
$last_reset = $results_array['last_reset']; |
|
49 |
$time_diff = time()-$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 |
|
|
58 |
$old_pass = $results_array['password']; |
|
59 |
|
|
60 |
// 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 |
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'"); |
|
72 |
|
|
73 |
if($database->is_error()) { |
|
74 |
// Error updating database |
|
75 |
$message = $database->get_error(); |
|
76 |
} else { |
|
77 |
// Setup email to send |
|
78 |
$mail_to = $email; |
|
79 |
$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO']; |
|
80 |
|
|
81 |
// Replace placeholders from language variable with values |
|
82 |
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}'); |
|
83 |
$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass); |
|
84 |
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']); |
|
85 |
|
|
86 |
// Try sending the email |
|
87 |
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { |
|
88 |
$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET']; |
|
89 |
$display_form = false; |
|
90 |
} else { |
|
91 |
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'"); |
|
92 |
$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL']; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
} else { |
|
99 |
// Email doesn't exist, so tell the user |
|
100 |
$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND']; |
|
101 |
} |
|
102 |
|
|
103 |
} else { |
|
104 |
$email = ''; |
|
105 |
} |
|
106 |
|
|
107 |
if(!isset($message)) { |
|
108 |
$message = $MESSAGE['FORGOT_PASS']['NO_DATA']; |
|
109 |
$message_color = '000000'; |
|
110 |
} else { |
|
111 |
$message_color = 'FF0000'; |
|
112 |
} |
|
113 |
|
|
114 |
?> |
|
115 |
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1> |
|
116 |
|
|
117 |
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot.php'; ?>" method="post"> |
|
118 |
<input type="hidden" name="url" value="{URL}" /> |
|
119 |
<table cellpadding="5" cellspacing="0" border="0" align="center" width="500"> |
|
120 |
<tr> |
|
121 |
<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2"> |
|
122 |
<?php echo $message; ?> |
|
123 |
</td> |
|
124 |
</tr> |
|
125 |
<?php if(!isset($display_form) OR $display_form != false) { ?> |
|
126 |
<tr> |
|
127 |
<td height="10" colspan="2"></td> |
|
128 |
</tr> |
|
129 |
<tr> |
|
130 |
<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td> |
|
131 |
<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td> |
|
132 |
<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> |
|
133 |
</tr> |
|
134 |
<!-- |
|
135 |
<tr> |
|
136 |
<td> </td> |
|
137 |
</tr> |
|
138 |
<tr style="display: {DISPLAY_FORM}"> |
|
139 |
<td height="10" colspan="2"></td> |
|
140 |
</tr> |
|
141 |
--> |
|
142 |
<?php } ?> |
|
143 |
</table> |
|
142 | 144 |
</form> |
Also available in: Unified diff
fix some PHP 5.3 deprecated functions