Project

General

Profile

1 4 ryan
<?php
2
3 17 stefan
// $Id$
4 4 ryan
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, Ryan Djurovich
9
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
if(!defined('WB_URL')) {
27 17 stefan
	header('Location: ../pages/index.php');
28 4 ryan
}
29
30
// Create new database object
31
$database = new database();
32
33
// Check if the user has already submitted the form, otherwise show it
34
if(isset($_POST['email']) AND $_POST['email'] != "") {
35
36
	$email = $_POST['email'];
37
38
	// Check if the email exists in the database
39 226 ryan
	$query = "SELECT user_id,username,display_name,email,last_reset FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'";
40 4 ryan
	$results = $database->query($query);
41
	if($results->numRows() > 0) {
42
		// Get the id, username, and email from the above db query
43
		$results_array = $results->fetchRow();
44
45 226 ryan
		// Check if the password has been reset in the last 2 hours
46
		$last_reset = $results_array['last_reset'];
47
		$time_diff = mktime()-$last_reset; // Time since last reset in seconds
48
		$time_diff = $time_diff/60/60; // Time since last reset in hours
49
		if($time_diff < 2) {
50
51
			// Tell the user that their password cannot be reset more than once per hour
52
			$message = $MESSAGE['FORGOT_PASS']['ALREADY_RESET'];
53
54
		} else {
55 4 ryan
56 226 ryan
			// Generate a random password then update the database with it
57
			$new_pass = '';
58
			$salt = "abchefghjkmnpqrstuvwxyz0123456789";
59
			srand((double)microtime()*1000000);
60
			$i = 0;
61
			while ($i <= 7) {
62
				$num = rand() % 33;
63
				$tmp = substr($salt, $num, 1);
64
				$new_pass = $new_pass . $tmp;
65
				$i++;
66
			}
67
68
			$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."' WHERE user_id = '".$results_array['user_id']."'");
69
70
			if($database->is_error()) {
71
				// Error updating database
72
				$message = $database->get_error();
73
			} else {
74
				// Setup email to send
75
				$mail_subject = 'Your login details...';
76
				$mail_to = $email;
77
				$mail_message = ''.
78 4 ryan
'Hello '.$results_array["display_name"].',
79
80
Your '.WEBSITE_TITLE.' administration login details are:
81
Username: '.$results_array["username"].'
82
Password: '.$new_pass.'
83
84
Your password has been reset to the one above.
85
This means that your old password will no longer work.
86
87 218 ryan
If you have received this message in error, please delete it immediatly.';
88 226 ryan
				// Try sending the email
89
				if(mail($mail_to, $mail_subject, $mail_message)) {
90
					$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET'];
91
					$display_form = false;
92
				} else {
93
					$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'];
94
				}
95 4 ryan
			}
96 226 ryan
		}
97 4 ryan
	} else {
98
		// Email doesn't exist, so tell the user
99
		$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];
100
	}
101
102
} else {
103
	$email = '';
104
}
105
106
if(!isset($message)) {
107
	$message = $MESSAGE['FORGOT_PASS']['NO_DATA'];
108
	$message_color = '000000';
109
} else {
110
	$message_color = 'FF0000';
111
}
112
113
?>
114
<h1 style="text-align: center;"><?php echo $MENU['FORGOT']; ?></h1>
115
116
<form name="forgot_pass" action="<?php echo WB_URL.'/account/forgot'.PAGE_EXTENSION; ?>" method="post">
117
	<input type="hidden" name="url" value="{URL}" />
118
		<table cellpadding="5" cellspacing="0" border="0" align="center" width="500">
119
		<tr>
120
			<td height="40" align="center" style="color: #<?php echo $message_color; ?>;" colspan="2">
121
			<?php echo $message; ?>
122
			</td>
123
		</tr>
124
		<?php if(!isset($display_form) OR $display_form != false) { ?>
125
		<tr>
126
			<td height="10" colspan="2"></td>
127
		</tr>
128
		<tr>
129
			<td width="165" height="30" align="right"><?php echo $TEXT['EMAIL']; ?>:</td>
130
			<td><input type="text" maxlength="30" name="email" value="<?php echo $email; ?>" style="width: 180px;" /></td>
131
		</tr>
132
		<tr height="30">
133
			<td>&nbsp;</td>
134
			<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>
135
		</tr>
136
		<tr style="display: {DISPLAY_FORM}">
137
			<td height="10" colspan="2"></td>
138
		</tr>
139
		<?php } ?>
140
		</table>
141 239 stefan
</form>