Project

General

Profile

« Previous | Next » 

Revision 226

Added by ryan over 18 years ago

Fixed bug #65 (last_reset check in account/forgot_form.php)

View differences:

trunk/wb/account/forgot_form.php
36 36
	$email = $_POST['email'];
37 37
	
38 38
	// Check if the email exists in the database
39
	$query = "SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'";
39
	$query = "SELECT user_id,username,display_name,email,last_reset FROM ".TABLE_PREFIX."users WHERE email = '".$wb->add_slashes($_POST['email'])."'";
40 40
	$results = $database->query($query);
41 41
	if($results->numRows() > 0) {
42 42
		// Get the id, username, and email from the above db query
43 43
		$results_array = $results->fetchRow();
44 44
		
45
		// Generate a random password then update the database with it
46
		$new_pass = '';
47
		$salt = "abchefghjkmnpqrstuvwxyz0123456789";
48
		srand((double)microtime()*1000000);
49
		$i = 0;
50
		while ($i <= 7) {
51
			$num = rand() % 33;
52
			$tmp = substr($salt, $num, 1);
53
			$new_pass = $new_pass . $tmp;
54
			$i++;
55
		}
45
		// 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 {
56 55
		
57
		$database->query("UPDATE ".TABLE_PREFIX."users SET password = '".md5($new_pass)."' WHERE user_id = '".$results_array['user_id']."'");
58
		
59
		if($database->is_error()) {
60
			// Error updating database
61
			$message = $database->get_error();
62
		} else {
63
			// Setup email to send
64
			$mail_subject = 'Your login details...';
65
			$mail_to = $email;
66
			$mail_message = ''.
56
			// 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 = ''.
67 78
'Hello '.$results_array["display_name"].', 
68 79

  
69 80
Your '.WEBSITE_TITLE.' administration login details are:
......
74 85
This means that your old password will no longer work.
75 86

  
76 87
If you have received this message in error, please delete it immediatly.';
77
			// Try sending the email
78
			if(mail($mail_to, $mail_subject, $mail_message)) {
79
				$message = $MESSAGE['FORGOT_PASS']['PASSWORD_RESET'];
80
				$display_form = false;
81
			} else {
82
				$message = $MESSAGE['FORGOT_PASS']['CANNOT_EMAIL'];
88
				// 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
				}
83 95
			}
84
		}
85
			
96
		}	
86 97
	} else {
87 98
		// Email doesn't exist, so tell the user
88 99
		$message = $MESSAGE['FORGOT_PASS']['EMAIL_NOT_FOUND'];

Also available in: Unified diff