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          Ryan Djurovich
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/forgot_form.php $
38
 * @author          Ryan Djurovich
39
 * @copyright       2004-2009, Ryan Djurovich
40
 *
41
 * @author          WebsiteBaker Project
42
 * @link			http://www.websitebaker2.org/
43
 * @copyright       2009-2010, Website Baker Org. e.V.
44
 * @link			http://start.websitebaker2.org/impressum-datenschutz.php
45
 * @license         http://www.gnu.org/licenses/gpl.html
46
 * @version         $Id: forgot_form.php 1262 2010-01-21 08:24:34Z Luisehahne $
47
 * @platform        WebsiteBaker 2.8.x
48
 * @requirements    PHP 4.3.4 and higher
49
 * @lastmodified    $Date: 2010-01-21 09:24:34 +0100 (Thu, 21 Jan 2010) $
50
 *
51
 */
52

    
53
if(!defined('WB_URL')) {
54
	header('Location: ../pages/index.php');
55
	exit(0);
56
}
57

    
58
// Create new database object
59
$database = new database();
60

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

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

    
108
				// Replace placeholders from language variable with values
109
				$search = array('{LOGIN_DISPLAY_NAME}', '{LOGIN_WEBSITE_TITLE}', '{LOGIN_NAME}', '{LOGIN_PASSWORD}');
110
				$replace = array($results_array['display_name'], WEBSITE_TITLE, $results_array['username'], $new_pass); 
111
				$mail_message = str_replace($search, $replace, $MESSAGE['SIGNUP2']['BODY_LOGIN_INFO']);
112

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

    
125
	} else {
126
		// Email doesn't exist, so tell the user
127
		$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];
128
	}
129
	
130
} else {
131
	$email = '';
132
}
133

    
134
if(!isset($message)) {
135
	$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
136
	$message_color = '000000';
137
} else {
138
	$message_color = 'FF0000';
139
}
140
	
141
?>
142
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
143

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