Project

General

Profile

1
<?php
2
/*
3
*
4
*                       About WebsiteBaker
5
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10
*                       LICENSE INFORMATION
11
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29
*/
30
/**
31
 *
32
 * @category        frontend
33
 * @package         account
34
 * @author          WebsiteBaker Project
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @link			http://www.websitebaker2.org/
38
 * @license         http://www.gnu.org/licenses/gpl.html
39
 * @platform        WebsiteBaker 2.8.x
40
 * @requirements    PHP 4.3.4 and higher
41
 * @version         $Id: forgot_form.php 1268 2010-01-22 17:21:02Z Luisehahne $
42
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/forgot_form.php $
43
 * @lastmodified    $Date: 2010-01-22 18:21:02 +0100 (Fri, 22 Jan 2010) $
44
 *
45
 */
46

    
47
if(!defined('WB_URL')) {
48
	header('Location: ../pages/index.php');
49
	exit(0);
50
}
51

    
52
// Create new database object
53
$database = new database();
54

    
55
// Check if the user has already submitted the form, otherwise show it
56
if(isset($_POST['email']) && $_POST['email'] != "" &&
57
    preg_match("/([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}/i", $_POST['email'])) {
58
	$email = strip_tags($_POST['email']);
59
	
60
	// Check if the email exists in the database
61
	$query = "SELECT user_id,username,display_name,email,last_reset,password FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'";
62
	$results = $database->query($query);
63
	if($results->numRows() > 0) {
64
	
65
		// Get the id, username, email, and last_reset from the above db query
66
		$results_array = $results->fetchRow();
67
		
68
		// Check if the password has been reset in the last 2 hours
69
		$last_reset = $results_array['last_reset'];
70
		$time_diff = time()-$last_reset; // Time since last reset in seconds
71
		$time_diff = $time_diff/60/60; // Time since last reset in hours
72
		if($time_diff < 2) {
73
			
74
			// Tell the user that their password cannot be reset more than once per hour
75
			$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
76
			
77
		} else {
78
		
79
			$old_pass = $results_array['password'];
80

    
81
			// Generate a random password then update the database with it
82
			$new_pass = '';
83
			$salt = "abchefghjkmnpqrstuvwxyz0123456789";
84
			srand((double)microtime()*1000000);
85
			$i = 0;
86
			while ($i <= 7) {
87
				$num = rand() % 33;
88
				$tmp = substr($salt, $num, 1);
89
				$new_pass = $new_pass . $tmp;
90
				$i++;
91
			}
92
			$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."', last_reset = '".time()."' WHERE user_id = '".$results_array['user_id']."'");
93
			
94
			if($database->is_error()) {
95
				// Error updating database
96
				$message = $database->get_error();
97
			} else {
98
				// Setup email to send
99
				$mail_to = $email;
100
				$mail_subject = $MESSAGE['SIGNUP2']['SUBJECT_LOGIN_INFO'];
101

    
102
				// Replace placeholders from language variable with values
103
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
104
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass); 
105
				$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
106

    
107
				// Try sending the email
108
				if($wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message)) { 
109
					$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET'];
110
					$display_form = false;
111
				} else {
112
					$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".$old_pass."' WHERE user_id = '".$results_array['user_id']."'");
113
					$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'];
114
				}
115
			}
116
		
117
		}
118

    
119
	} else {
120
		// Email doesn't exist, so tell the user
121
		$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];
122
	}
123
	
124
} else {
125
	$email = '';
126
}
127

    
128
if(!isset($message)) {
129
	$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
130
	$message_color = '000000';
131
} else {
132
	$message_color = 'FF0000';
133
}
134
	
135
?>
136
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
137

    
138
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot.php'; ?>" method="post">
139
	<input type="hidden" name="url" value="{URL}" />
140
		<table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
141
		<tr>
142
			<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2">
143
			<?php echo $message; ?>
144
			</td>
145
		</tr>
146
		<?php if(!isset($display_form) OR $display_form != false) { ?>
147
		<tr>
148
			<td height="10" colspan="2"></td>
149
		</tr>
150
		<tr>
151
			<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td>
152
			<td><input type="text" maxlength="255" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td>
153
			<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>
154
		</tr>
155
<!--
156
		<tr>
157
			<td>&nbsp;</td>
158
		</tr>
159
		<tr style="display: {DISPLAY_FORM}">
160
			<td height="10" colspan="2"></td>
161
		</tr>
162
-->
163
		<?php } ?>
164
		</table>
165
</form>
(4-4/14)