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