Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        frontend
5
 * @package         account
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, Website Baker Org. e.V.
8
 * @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: password.php 1777 2012-10-01 16:16:26Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/password.php $
14
 * @lastmodified    $Date: 2012-10-01 18:16:26 +0200 (Mon, 01 Oct 2012) $
15
 *
16
 */
17

    
18
/* -------------------------------------------------------- */
19
// Must include code to stop this file being accessed directly
20
if(!defined('WB_PATH')) {
21
	require_once(dirname(dirname(__FILE__)).'/framework/globalExceptionHandler.php');
22
	throw new IllegalFileException();
23
}
24
/* -------------------------------------------------------- */
25

    
26
// Get entered values
27
	$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
// Validate values
39
	if (md5($sCurrentPassword) != $database->get_one($sql)) {
40
		$error[] = $MESSAGE['PREFERENCES_CURRENT_PASSWORD_INCORRECT'];
41
	}else {
42
		if(strlen($sNewPassword) < $iMinPassLength) {
43
			$error[] = $MESSAGE['USERS_PASSWORD_TOO_SHORT'];
44
		}else {
45
			if($sNewPassword != $sNewPasswordRetyped) {
46
				$error[] = $MESSAGE['USERS_PASSWORD_MISMATCH'];
47
			}else {
48
				$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
// Update the database
55
					$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
				}
64
			}
65
		}
66
	}
(15-15/22)