From 25f5e4f18f9aed7272b3f3f9e8647c287b689b29 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 17 Sep 2015 15:36:04 +0200 Subject: [PATCH 1/2] [ticket/12577] Lazy initialize the password manager PHPBB3-12577 --- phpBB/phpbb/passwords/manager.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/passwords/manager.php b/phpBB/phpbb/passwords/manager.php index aa9147ecf4..03729815ba 100644 --- a/phpBB/phpbb/passwords/manager.php +++ b/phpBB/phpbb/passwords/manager.php @@ -49,6 +49,10 @@ class manager */ protected $config; + private $initialized = false; + private $hashing_algorithms; + private $defaults; + /** * Construct a passwords object * @@ -62,9 +66,18 @@ class manager { $this->config = $config; $this->helper = $helper; + $this->hashing_algorithms = $hashing_algorithms; + $this->defaults = $defaults; + } - $this->fill_type_map($hashing_algorithms); - $this->register_default_type($defaults); + protected function initialize() + { + if (!$this->initialized) + { + $this->initialized = true; + $this->fill_type_map($this->hashing_algorithms); + $this->register_default_type($this->defaults); + } } /** @@ -144,6 +157,8 @@ class manager return false; } + $this->initialize(); + // Be on the lookout for multiple hashing algorithms // 2 is correct: H\2a > 2, H\P > 2 if (strlen($match[1]) > 2) @@ -192,6 +207,8 @@ class manager return false; } + $this->initialize(); + // Try to retrieve algorithm by service name if type doesn't // start with dollar sign if (!is_array($type) && strpos($type, '$') !== 0 && isset($this->algorithms[$type])) @@ -242,6 +259,8 @@ class manager return false; } + $this->initialize(); + // First find out what kind of hash we're dealing with $stored_hash_type = $this->detect_algorithm($hash); if ($stored_hash_type == false) @@ -297,6 +316,8 @@ class manager */ public function combined_hash_password($password_hash, $type) { + $this->initialize(); + $data = array( 'prefix' => '$', 'settings' => '$', From f9f7f935b4fe2742cd84d100be1dc03fd66919ec Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 18 Sep 2015 19:54:06 +0200 Subject: [PATCH 2/2] [ticket/12577] Docblock PHPBB3-12577 --- phpBB/phpbb/passwords/manager.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/passwords/manager.php b/phpBB/phpbb/passwords/manager.php index 03729815ba..b2caba81f2 100644 --- a/phpBB/phpbb/passwords/manager.php +++ b/phpBB/phpbb/passwords/manager.php @@ -49,18 +49,28 @@ class manager */ protected $config; + /** + * @var bool Whether or not initialized() has been called + */ private $initialized = false; + + /** + * @var array Hashing driver service collection + */ private $hashing_algorithms; + + /** + * @var array List of default driver types + */ private $defaults; /** * Construct a passwords object * - * @param \phpbb\config\config $config phpBB configuration - * @param array $hashing_algorithms Hashing driver - * service collection - * @param \phpbb\passwords\helper $helper Passwords helper object - * @param array $defaults List of default driver types + * @param \phpbb\config\config $config phpBB configuration + * @param array $hashing_algorithms Hashing driver service collection + * @param \phpbb\passwords\helper $helper Passwords helper object + * @param array $defaults List of default driver types */ public function __construct(\phpbb\config\config $config, $hashing_algorithms, helper $helper, $defaults) { @@ -70,6 +80,9 @@ class manager $this->defaults = $defaults; } + /** + * Initialize the internal state + */ protected function initialize() { if (!$this->initialized)