[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/passwords/ -> helper.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\passwords;
  15  
  16  class helper
  17  {
  18      /**
  19      * Get hash settings from combined hash
  20      *
  21      * @param string $hash Password hash of combined hash
  22      *
  23      * @return array An array containing the hash settings for the hash
  24      *        types in successive order as described by the combined
  25      *        password hash or an empty array if hash does not
  26      *        properly fit the combined hash format
  27      */
  28  	public function get_combined_hash_settings($hash)
  29      {
  30          $output = array();
  31  
  32          preg_match('#^\$([a-zA-Z0-9\\\]*?)\$#', $hash, $match);
  33          $hash_settings = substr($hash, strpos($hash, $match[1]) + strlen($match[1]) + 1);
  34          $matches = explode('\\', $match[1]);
  35          foreach ($matches as $cur_type)
  36          {
  37              $dollar_position = strpos($hash_settings, '$');
  38              $output[] = substr($hash_settings, 0, ($dollar_position != false) ? $dollar_position : strlen($hash_settings));
  39              $hash_settings = substr($hash_settings, $dollar_position + 1);
  40          }
  41  
  42          return $output;
  43      }
  44  
  45      /**
  46      * Combine hash prefixes, settings, and actual hash
  47      *
  48      * @param array $data Array containing the keys 'prefix' and 'settings'.
  49      *            It will hold the prefixes and settings
  50      * @param string $type Data type of the supplied value
  51      * @param string $value Value that should be put into the data array
  52      *
  53      * @return string|null Return complete combined hash if type is neither
  54      *            'prefix' nor 'settings', nothing if it is
  55      */
  56  	public function combine_hash_output(&$data, $type, $value)
  57      {
  58          if ($type == 'prefix')
  59          {
  60              $data[$type] .= ($data[$type] !== '$') ? '\\' : '';
  61              $data[$type] .= str_replace('$', '', $value);
  62          }
  63          else if ($type == 'settings')
  64          {
  65              $data[$type] .= ($data[$type] !== '$') ? '$' : '';
  66              $data[$type] .= $value;
  67          }
  68          else
  69          {
  70              // Return full hash
  71              return $data['prefix'] . $data['settings'] . '$' . $value;
  72          }
  73      }
  74  
  75      /**
  76      * Rebuild hash for hashing functions
  77      *
  78      * @param string $prefix Hash prefix
  79      * @param string $settings Hash settings
  80      *
  81      * @return string Rebuilt hash for hashing functions
  82      */
  83  	public function rebuild_hash($prefix, $settings)
  84      {
  85          $rebuilt_hash = $prefix;
  86          if (strpos($settings, '\\') !== false)
  87          {
  88              $settings = str_replace('\\', '$', $settings);
  89          }
  90          $rebuilt_hash .= $settings;
  91          return $rebuilt_hash;
  92      }
  93  
  94      /**
  95      * Obtain only the actual hash after the prefixes
  96      *
  97      * @param string        $hash The full password hash
  98      * @return string    Actual hash (incl. settings)
  99      */
 100  	public function obtain_hash_only($hash)
 101      {
 102          return substr($hash, strripos($hash, '$') + 1);
 103      }
 104  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1