Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         account
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: forgot_form.php 1566 2012-01-07 02:21:26Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/forgot_form.php $
14
 * @lastmodified    $Date: 2012-01-07 03:21:26 +0100 (Sat, 07 Jan 2012) $
15
 *
16
 */
17

    
18
// Must include code to stop this file being access directly
19
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
20
// Check if the user has already submitted the form, otherwise show it
21
if(isset($_POST['email']) && $_POST['email'] != "" )
22
{
23
	$email = strip_tags($_POST['email']);
24
// Check if the email exists in the database
25
	$sql  = 'SELECT `user_id`,`username`,`display_name`,`email`,`last_reset`,`password` '.
26
	        'FROM `'.TABLE_PREFIX.'users` '.
27
	        'WHERE `email`=\''.$wb->add_slashes($_POST['email']).'\'';
28
	if(($results = $database->query($sql)))
29
	{
30
		if(($results_array = $results->fetchRow()))
31
		{ // Get the id, username, email, and last_reset from the above db query
32
		// Check if the password has been reset in the last 2 hours
33
			if( (time() - (int)$results_array['last_reset']) < (2 * 3600) ) {
34
			// Tell the user that their password cannot be reset more than once per hour
35
				$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
36
			} else {
37
				require_once(WB_PATH.'/framework/PasswordHash.php');
38
				$pwh = new PasswordHash(0, true);
39
				$old_pass = $results_array['password'];
40
			// Generate a random password then update the database with it
41
				$new_pass = $pwh->NewPassword();
42
				$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
43
				       'SET `password`=\''.$pwh->HashPassword($new_pass, true).'\', '.
44
				           '`last_reset`='.time().' '.
45
				       'WHERE `user_id`='.(int)$results_array['user_id'];
46
				unset($pwh); // destroy $pwh-Object
47
				if($database->query($sql))
48
				{ // Setup email to send
49
					$mail_to = $email;
50
					$mail_subject = $MESSAGE['SIGNUP2_SUBJECT_LOGIN_INFO'];
51
				// Replace placeholders from language variable with values
52
					$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
53
					$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass);
54
					$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2_BODY_LOGIN_FORGOT']);
55
				// Try sending the email
56
					if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) {
57
						$message = $MESSAGE['FORGOT_PASS_PASSWORD_RESET'];
58
						$display_form = false;
59
					}else { // snd mail failed, rollback
60
						$sql = 'UPDATE `'.TABLE_PREFIX.'users` '.
61
						       'SET `password`=\''.$old_pass.'\' '.
62
						       'WHERE `user_id`='.(int)$results_array['user_id'];
63
						$database->query($sql);
64
						$message = $MESSAGE['FORGOT_PASS_CANNOT_EMAIL'];
65
					}
66
				}else { // Error updating database
67
					$message = $MESSAGE['RECORD_MODIFIED_FAILED'];
68
					if(DEBUG) {
69
						$message .= '<br />'.$database->get_error();
70
						$message .= '<br />'.$sql;
71
					}
72
				}
73
			}
74
		}else { // no record found - Email doesn't exist, so tell the user
75
			$message = $MESSAGE['FORGOT_PASS_EMAIL_NOT_FOUND'];
76
		}
77
	} else { // Query failed
78
		$message = 'SystemError:: Database query failed!';
79
		if(DEBUG) {
80
			$message .= '<br />'.$database->get_error();
81
			$message .= '<br />'.$sql;
82
		}
83
	}
84
} else {
85
	$email = '';
86
}
87

    
88
if(isset($message) && $message != '') {
89
	$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
90
	$message_color = 'FF0000';
91
} else {
92
	$message = $MESSAGE['FORGOT_PASS_NO_DATA'];
93
	$message_color = '000000';
94
}
95

    
96
$page_id = (!empty($_SESSION['PAGE_ID']) ? $_SESSION['PAGE_ID'] : 0);
97
$_SESSION['PAGE_LINK'] = get_page_link( $page_id );
98
$_SESSION['HTTP_REFERER'] = (($_SESSION['PAGE_LINK']!='') ? page_link($_SESSION['PAGE_LINK']) : WB_URL);
99

    
100
?>
101
<div style="margin: 1em auto;">
102
	<button type="button" value="cancel" onClick="javascript: window.location = '<?php print $_SESSION['HTTP_REFERER'] ?>';"><?php print $TEXT['CANCEL'] ?></button>
103
</div>
104
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
105
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot.php'; ?>" method="post">
106
	<input type="hidden" name="url" value="{URL}" />
107
		<table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
108
		<tr>
109
			<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2">
110
			<?php echo $message; ?>
111
			</td>
112
		</tr>
113
<?php if(!isset($display_form) OR $display_form != false) { ?>
114
		<tr>
115
			<td height="10" colspan="2"></td>
116
		</tr>
117
		<tr>
118
			<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td>
119
			<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td>
120
			<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>
121
		</tr>
122
<?php } ?>
123
		</table>
124
</form>
(4-4/16)