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 1777 Luisehahne
if(!defined('WB_PATH')) {
21
	require_once(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php');
22
	throw new IllegalFileException();
23 1773 Luisehahne
}
24
/* -------------------------------------------------------- */
25 1386 Luisehahne
26 1508 Luisehahne
// Get entered values
27 1569 darkviper
	$iMinPassLength = 6;
28
	$sCurrentPassword = $wb->get_post('current_password');
29
	$sCurrentPassword = (is_null($sCurrentPassword) ? '' : $sCurrentPassword);
30
	$sNewPassword = $wb->get_post('new_password');
31
	$sNewPassword = is_null($sNewPassword) ? '' : $sNewPassword;
32
	$sNewPasswordRetyped = $wb->get_post('new_password2');
33
	$sNewPasswordRetyped= is_null($sNewPasswordRetyped) ? '' : $sNewPasswordRetyped;
34
// Check existing password
35
	$sql  = 'SELECT `password` ';
36
	$sql .= 'FROM `'.TABLE_PREFIX.'users` ';
37
	$sql .= 'WHERE `user_id` = '.$wb->get_user_id();
38 1386 Luisehahne
// Validate values
39 1569 darkviper
	if (md5($sCurrentPassword) != $database->get_one($sql)) {
40
		$error[] = $MESSAGE['PREFERENCES_CURRENT_PASSWORD_INCORRECT'];
41 1508 Luisehahne
	}else {
42 1569 darkviper
		if(strlen($sNewPassword) < $iMinPassLength) {
43
			$error[] = $MESSAGE['USERS_PASSWORD_TOO_SHORT'];
44 1508 Luisehahne
		}else {
45 1569 darkviper
			if($sNewPassword != $sNewPasswordRetyped) {
46
				$error[] = $MESSAGE['USERS_PASSWORD_MISMATCH'];
47 1508 Luisehahne
			}else {
48 1569 darkviper
				$pattern = '/[^'.$wb->password_chars.']/';
49
				if (preg_match($pattern, $sNewPassword)) {
50
					$error[] = $MESSAGE['PREFERENCES_INVALID_CHARS'];
51
				}else {
52
// generate new password hash
53
					$sPwHashNew = md5($sNewPassword);
54 1386 Luisehahne
// Update the database
55 1569 darkviper
					$sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
56
					$sql .= 'SET `password`=\''.$sPwHashNew.'\' ';
57
					$sql .= 'WHERE `user_id`='.$wb->get_user_id();
58
					if ($database->query($sql)) {
59
						$success[] = $MESSAGE['PREFERENCES_PASSWORD_CHANGED'];
60
					}else {
61
						$error[] = $database->get_error();
62
					}
63 1508 Luisehahne
				}
64
			}
65
		}
66
	}