<commit_before><?php
namespace wcf\data\user;
use wcf\data\user\group\UserGroup;
use wcf\data\user\UserList;
use wcf\data\DatabaseObject;
use wcf\system\cache\builder\UserOptionCacheBuilder;
use wcf\system\language\LanguageFactory;
use wcf\system\request\IRouteController;
use wcf\system\user\storage\UserStorageHandler;
use wcf\system\WCF;
use wcf\util\PasswordUtil;

/**
 * Represents a user.
 * 
 * @author	<NAME>
 * @copyright	2001-2013 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	data.user
 * @category	Community Framework
 */
final class User extends DatabaseObject implements IRouteController {
	/**
	 * @see	\wcf\data\DatabaseObject::$databaseTableName
	 */
	protected static $databaseTableName = 'user';
	
	/**
	 * @see	\wcf\data\DatabaseObject::$databaseTableIndexName
	 */
	protected static $databaseTableIndexName = 'userID';
	
	/**
	 * list of group ids
	 * @var	array<integer>
	 */
	protected $groupIDs = null;
	
	/**
	 * true, if user has access to the ACP
	 * @var	boolean
	 */
	protected $hasAdministrativePermissions = null;
	
	/**
	 * list of language ids
	 * @var	array<integer>
	 */
	protected $languageIDs = null;
	
	/**
	 * date time zone object
	 * @var	DateTimeZone
	 */
	protected $timezoneObj = null;
	
	/**
	 * list of user options
	 * @var	array<string>
	 */
	protected static $userOptions = null;
	
	/**
	 * @see	\wcf\data\DatabaseObject::__construct()
	 */
	public function __construct($id, $row = null, DatabaseObject $object = null) {
		if ($id !== null) {
			$sql = "SELECT		user_option_value.*, user_table.*
				FROM		wcf".WCF_N."_user user_table
				LEFT JOIN	wcf".WCF_N."_user_option_value user_option_value
				ON		(user_option_value.userID = user_table.userID)
				WHERE		user_table.userID = ?";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute(array($id));
			$row = $statement->fetchArray();
			
			// enforce data type 'array'
			if ($row === false) $row = array();
		}
		else if ($object !== null) {
			$row = $object->data;
		}
		
		$this->handleData($row);
	}
	
	/**
	 * Returns true if the given password is the correct password for this user.
	 * 
	 * @param	string		$password
	 * @return	boolean		password correct
	 */
	public function checkPassword($password) {
		$isValid = false;
		$rebuild = false;
		
		// check if password is a valid bcrypt hash
		if (PasswordUtil::isBlowfish($this->password)) {
			if (PasswordUtil::isDifferentBlowfish($this->password)) {
				$rebuild = true;
			}
			
			// password is correct
			if (PasswordUtil::secureCompare($this->password, PasswordUtil::getDoubleSaltedHash($password, $this->password))) {
				$isValid = true;
			}
		}
		else {
			// different encryption type
			if (PasswordUtil::checkPassword($this->username, $password, $this->password)) {
				$isValid = true;
				$rebuild = true;
			}
		}
		
		// create new password hash, either different encryption or different blowfish cost factor
		if ($rebuild) {
			$userEditor = new UserEditor($this);
			$userEditor->update(array(
				'password' => $password
			));
		}
		
		return $isValid;
	}
	
	/**
	 * Returns true if the given password hash from a cookie is the correct password for this user.
	 * 
	 * @param	string		$passwordHash
	 * @return	boolean		password correct
	 */
	public function checkCookiePassword($passwordHash) {
		if (PasswordUtil::isBlowfish($this->password) && PasswordUtil::secureCompare($this->password, PasswordUtil::getSaltedHash($passwordHash, $this->password))) {
			return true;<commit_msg>Fix rebuilding of outdated blowfish passwords<commit_after><?php
namespace wcf\data\user;
use wcf\data\user\group\UserGroup;
use wcf\data\user\UserList;
use wcf\data\DatabaseObject;
use wcf\system\cache\builder\UserOptionCacheBuilder;
use wcf\system\language\LanguageFactory;
use wcf\system\request\IRouteController;
use wcf\system\user\storage\UserStorageHandler;
use wcf\system\WCF;
use wcf\util\PasswordUtil;

/**
 * Represents a user.
 * 
 * @author	<NAME>
 * @copyright	2001-2013 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	com.woltlab.wcf
 * @subpackage	data.user
 * @category	Community Framework
 */
final class User extends DatabaseObject implements IRouteController {
	/**
	 * @see	\wcf\data\DatabaseObject::$databaseTableName
	 */
	protected static $databaseTableName = 'user';
	
	/**
	 * @see	\wcf\data\DatabaseObject::$databaseTableIndexName
	 */
	protected static $databaseTableIndexName = 'userID';
	
	/**
	 * list of group ids
	 * @var	array<integer>
	 */
	protected $groupIDs = null;
	
	/**
	 * true, if user has access to the ACP
	 * @var	boolean
	 */
	protected $hasAdministrativePermissions = null;
	
	/**
	 * list of language ids
	 * @var	array<integer>
	 */
	protected $languageIDs = null;
	
	/**
	 * date time zone object
	 * @var	DateTimeZone
	 */
	protected $timezoneObj = null;
	
	/**
	 * list of user options
	 * @var	array<string>
	 */
	protected static $userOptions = null;
	
	/**
	 * @see	\wcf\data\DatabaseObject::__construct()
	 */
	public function __construct($id, $row = null, DatabaseObject $object = null) {
		if ($id !== null) {
			$sql = "SELECT		user_option_value.*, user_table.*
				FROM		wcf".WCF_N."_user user_table
				LEFT JOIN	wcf".WCF_N."_user_option_value user_option_value
				ON		(user_option_value.userID = user_table.userID)
				WHERE		user_table.userID = ?";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute(array($id));
			$row = $statement->fetchArray();
			
			// enforce data type 'array'
			if ($row === false) $row = array();
		}
		else if ($object !== null) {
			$row = $object->data;
		}
		
		$this->handleData($row);
	}
	
	/**
	 * Returns true if the given password is the correct password for this user.
	 * 
	 * @param	string		$password
	 * @return	boolean		password correct
	 */
	public function checkPassword($password) {
		$isValid = false;
		$rebuild = false;
		
		// check if password is a valid bcrypt hash
		if (PasswordUtil::isBlowfish($this->password)) {
			if (PasswordUtil::isDifferentBlowfish($this->password)) {
				$rebuild = true;
			}
			
			// password is correct
			if (PasswordUtil::secureCompare($this->password, PasswordUtil::getDoubleSaltedHash($password, $this->password))) {
				$isValid = true;
			}
		}
		else {
			// different encryption type
			if (PasswordUtil::checkPassword($this->username, $password, $this->password)) {
				$isValid = true;
				$rebuild = true;
			}
		}
		
		// create new password hash, either different encryption or different blowfish cost factor
		if ($rebuild && $isValid) {
			$userEditor = new UserEditor($this);
			$userEditor->update(array(
				'password' => <PASSWORD>
			));
		}
		
		return $isValid;
	}
	
	/**
	 * Returns true if the given password hash from a cookie is the correct password for this user.
	 * 
	 * @param	string		$passwordHash
	 * @return	boolean		password correct
	 */
	public function checkCookiePassword($passwordHash) {
		if (PasswordUtil::isBlowfish($this->password) && PasswordUtil::secureCompare($this->password, PasswordUtil::getSaltedHash($passwordHash, $this->password))) {
			return true;
{'fraction_non_alphanumeric': 0.13384848902994342, 'fraction_numerical': 0.0022078101283289635, 'mean_word_length': 3.700389105058366, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930346', 'n_tokens_mistral': 2587, 'n_tokens_neox': 2247, 'n_words': 567}