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 1773 2012-09-27 23:42:13Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/account/password.php $
14
 * @lastmodified    $Date: 2012-09-28 01:42:13 +0200 (Fri, 28 Sep 2012) $
15
 *
16
 */
17

    
18
/* -------------------------------------------------------- */
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

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