Project

General

Profile

1 1386 Luisehahne
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         account
6
 * @author          WebsiteBaker Project
7 1569 darkviper
 * @copyright       2009-2012, Website Baker Org. e.V.
8 1386 Luisehahne
 * @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$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16
 */
17
18 1773 Luisehahne
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
24
}
25
/* -------------------------------------------------------- */
26 1386 Luisehahne
27 1508 Luisehahne
// Get entered values
28 1569 darkviper
	$iMinPassLength = 6;
29
	$sCurrentPassword = $wb->get_post('current_password');
30
	$sCurrentPassword = (is_null($sCurrentPassword) ? '' : $sCurrentPassword);
31
	$sNewPassword = $wb->get_post('new_password');
32
	$sNewPassword = is_null($sNewPassword) ? '' : $sNewPassword;
33
	$sNewPasswordRetyped = $wb->get_post('new_password2');
34
	$sNewPasswordRetyped= is_null($sNewPasswordRetyped) ? '' : $sNewPasswordRetyped;
35
// Check existing password
36
	$sql  = 'SELECT `password` ';
37
	$sql .= 'FROM `'.TABLE_PREFIX.'users` ';
38
	$sql .= 'WHERE `user_id` = '.$wb->get_user_id();
39 1386 Luisehahne
// Validate values
40 1569 darkviper
	if (md5($sCurrentPassword) != $database->get_one($sql)) {
41
		$error[] = $MESSAGE['PREFERENCES_CURRENT_PASSWORD_INCORRECT'];
42 1508 Luisehahne
	}else {
43 1569 darkviper
		if(strlen($sNewPassword) < $iMinPassLength) {
44
			$error[] = $MESSAGE['USERS_PASSWORD_TOO_SHORT'];
45 1508 Luisehahne
		}else {
46 1569 darkviper
			if($sNewPassword != $sNewPasswordRetyped) {
47
				$error[] = $MESSAGE['USERS_PASSWORD_MISMATCH'];
48 1508 Luisehahne
			}else {
49 1569 darkviper
				$pattern = '/[^'.$wb->password_chars.']/';
50
				if (preg_match($pattern, $sNewPassword)) {
51
					$error[] = $MESSAGE['PREFERENCES_INVALID_CHARS'];
52
				}else {
53
// generate new password hash
54
					$sPwHashNew = md5($sNewPassword);
55 1386 Luisehahne
// Update the database
56 1569 darkviper
					$sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
57
					$sql .= 'SET `password`=\''.$sPwHashNew.'\' ';
58
					$sql .= 'WHERE `user_id`='.$wb->get_user_id();
59
					if ($database->query($sql)) {
60
						$success[] = $MESSAGE['PREFERENCES_PASSWORD_CHANGED'];
61
					}else {
62
						$error[] = $database->get_error();
63
					}
64 1508 Luisehahne
				}
65
			}
66
		}
67
	}