1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category frontend
|
5
|
* @package account
|
6
|
* @author WebsiteBaker Project
|
7
|
* @copyright 2004-2009, Ryan Djurovich
|
8
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
9
|
* @link http://www.websitebaker2.org/
|
10
|
* @license http://www.gnu.org/licenses/gpl.html
|
11
|
* @platform WebsiteBaker 2.8.x
|
12
|
* @requirements PHP 5.2.2 and higher
|
13
|
* @version $Id: forgot_form.php 1420 2011-01-26 17:43:56Z Luisehahne $
|
14
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/tags/2.8.2/wb/account/forgot_form.php $
|
15
|
* @lastmodified $Date: 2011-01-26 18:43:56 +0100 (Wed, 26 Jan 2011) $
|
16
|
*
|
17
|
*/
|
18
|
|
19
|
// Must include code to stop this file being access directly
|
20
|
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
|
21
|
|
22
|
// Create new database object
|
23
|
// $database = new database();
|
24
|
|
25
|
// Check if the user has already submitted the form, otherwise show it
|
26
|
if(isset($_POST['email']) && $_POST['email'] != "" &&
|
27
|
preg_match("/([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}/i", $_POST['email'])) {
|
28
|
$email = strip_tags($_POST['email']);
|
29
|
|
30
|
// Check if the email exists in the database
|
31
|
$query = "SELECT user_id,username,display_name,email,last_reset,password FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'";
|
32
|
$results = $database->query($query);
|
33
|
if($results->numRows() > 0) {
|
34
|
|
35
|
// Get the id, username, email, and last_reset from the above db query
|
36
|
$results_array = $results->fetchRow();
|
37
|
|
38
|
// Check if the password has been reset in the last 2 hours
|
39
|
$last_reset = $results_array['last_reset'];
|
40
|
$time_diff = time()-$last_reset; // Time since last reset in seconds
|
41
|
$time_diff = $time_diff/60/60; // Time since last reset in hours
|
42
|
if($time_diff < 2) {
|
43
|
|
44
|
// Tell the user that their password cannot be reset more than once per hour
|
45
|
$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
|
46
|
|
47
|
} else {
|
48
|
|
49
|
$old_pass = $results_array['password'];
|
50
|
|
51
|
// Generate a random password then update the database with it
|
52
|
$new_pass = '';
|
53
|
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
|
54
|
srand((double)microtime()*1000000);
|
55
|
$i = 0;
|
56
|
while ($i <= 7) {
|
57
|
$num = rand() % 33;
|
58
|
$tmp = substr($salt, $num, 1);
|
59
|
$new_pass = $new_pass . $tmp;
|
60
|
$i++;
|
61
|
}
|
62
|
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'");
|
63
|
|
64
|
if($database->is_error()) {
|
65
|
// Error updating database
|
66
|
$message = $database->get_error();
|
67
|
} else {
|
68
|
// Setup email to send
|
69
|
$mail_to = $email;
|
70
|
$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
|
71
|
|
72
|
// Replace placeholders from language variable with values
|
73
|
$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
|
74
|
$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
|
75
|
$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_FORGOT']);
|
76
|
|
77
|
// Try sending the email
|
78
|
if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
|
79
|
$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET'];
|
80
|
$display_form = false;
|
81
|
} else {
|
82
|
$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'");
|
83
|
$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'];
|
84
|
}
|
85
|
}
|
86
|
|
87
|
}
|
88
|
|
89
|
} else {
|
90
|
// Email doesn't exist, so tell the user
|
91
|
$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];
|
92
|
}
|
93
|
|
94
|
} else {
|
95
|
$email = '';
|
96
|
}
|
97
|
|
98
|
if(!isset($message)) {
|
99
|
$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
|
100
|
$message_color = '000000';
|
101
|
} else {
|
102
|
$message_color = 'FF0000';
|
103
|
}
|
104
|
|
105
|
?>
|
106
|
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
|
107
|
|
108
|
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot.php'; ?>" method="post">
|
109
|
<input type="hidden" name="url" value="{URL}" />
|
110
|
<table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
|
111
|
<tr>
|
112
|
<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2">
|
113
|
<?php echo $message; ?>
|
114
|
</td>
|
115
|
</tr>
|
116
|
<?php if(!isset($display_form) OR $display_form != false) { ?>
|
117
|
<tr>
|
118
|
<td height="10" colspan="2"></td>
|
119
|
</tr>
|
120
|
<tr>
|
121
|
<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td>
|
122
|
<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td>
|
123
|
<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>
|
124
|
</tr>
|
125
|
<!--
|
126
|
<tr>
|
127
|
<td> </td>
|
128
|
</tr>
|
129
|
<tr style="display: {DISPLAY_FORM}">
|
130
|
<td height="10" colspan="2"></td>
|
131
|
</tr>
|
132
|
-->
|
133
|
<?php } ?>
|
134
|
</table>
|
135
|
</form>
|