diff options
Diffstat (limited to 'phpBB/phpbb/passwords/driver/helper.php')
| -rw-r--r-- | phpBB/phpbb/passwords/driver/helper.php | 49 | 
1 files changed, 41 insertions, 8 deletions
| diff --git a/phpBB/phpbb/passwords/driver/helper.php b/phpBB/phpbb/passwords/driver/helper.php index 4b8dc9a123..f80c3e3df6 100644 --- a/phpBB/phpbb/passwords/driver/helper.php +++ b/phpBB/phpbb/passwords/driver/helper.php @@ -1,21 +1,22 @@  <?php  /**  * -* @package phpBB3 -* @copyright (c) 2013 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */  namespace phpbb\passwords\driver; -/** -* @package passwords -*/  class helper  {  	/** -	* @var phpbb\config\config +	* @var \phpbb\config\config  	*/  	protected $config; @@ -28,7 +29,7 @@ class helper  	/**  	* Construct a driver helper object  	* -	* @param phpbb\config\config $config phpBB configuration +	* @param \phpbb\config\config $config phpBB configuration  	*/  	public function __construct(\phpbb\config\config $config)  	{ @@ -141,4 +142,36 @@ class helper  		}  		return $random;  	} + +	/** +	 * Compare two strings byte by byte +	 * +	 * @param string $string_a The first string +	 * @param string $string_b The second string +	 * +	 * @return bool True if strings are the same, false if not +	 */ +	public function string_compare($string_a, $string_b) +	{ +		// Return if input variables are not strings or if length does not match +		if (!is_string($string_a) || !is_string($string_b) || strlen($string_a) != strlen($string_b)) +		{ +			return false; +		} + +		// Use hash_equals() if it's available +		if (function_exists('hash_equals')) +		{ +			return hash_equals($string_a, $string_b); +		} + +		$difference = 0; + +		for ($i = 0; $i < strlen($string_a) && $i < strlen($string_b); $i++) +		{ +			$difference |= ord($string_a[$i]) ^ ord($string_b[$i]); +		} + +		return $difference === 0; +	}  } | 
