Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

helper.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 3.22 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\passwords\driver;
 015   
 016  class helper
 017  {
 018      /**
 019      * @var \phpbb\config\config
 020      */
 021      protected $config;
 022   
 023      /**
 024      * base64 alphabet
 025      * @var string
 026      */
 027      public $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
 028   
 029      /**
 030      * Construct a driver helper object
 031      *
 032      * @param \phpbb\config\config $config phpBB configuration
 033      */
 034      public function __construct(\phpbb\config\config $config)
 035      {
 036          $this->config = $config;
 037      }
 038   
 039      /**
 040      * Base64 encode hash
 041      *
 042      * @param string $input Input string
 043      * @param int $count Input string length
 044      *
 045      * @return string base64 encoded string
 046      */
 047      public function hash_encode64($input, $count)
 048      {
 049          $output = '';
 050          $i = 0;
 051   
 052          do
 053          {
 054              $value = ord($input[$i++]);
 055              $output .= $this->itoa64[$value & 0x3f];
 056   
 057              if ($i < $count)
 058              {
 059                  $value |= ord($input[$i]) << 8;
 060              }
 061   
 062              $output .= $this->itoa64[($value >> 6) & 0x3f];
 063   
 064              if ($i++ >= $count)
 065              {
 066                  break;
 067              }
 068   
 069              if ($i < $count)
 070              {
 071                  $value |= ord($input[$i]) << 16;
 072              }
 073   
 074              $output .= $this->itoa64[($value >> 12) & 0x3f];
 075   
 076              if ($i++ >= $count)
 077              {
 078                  break;
 079              }
 080   
 081              $output .= $this->itoa64[($value >> 18) & 0x3f];
 082          }
 083          while ($i < $count);
 084   
 085          return $output;
 086      }
 087   
 088      /**
 089      * Return unique id
 090      *
 091      * @param string $extra Additional entropy
 092      *
 093      * @return string Unique id
 094      */
 095      public function unique_id($extra = 'c')
 096      {
 097          static $dss_seeded = false;
 098   
 099          $val = $this->config['rand_seed'] . microtime();
 100          $val = md5($val);
 101          $this->config['rand_seed'] = md5($this->config['rand_seed'] . $val . $extra);
 102   
 103          if ($dss_seeded !== true && ($this->config['rand_seed_last_update'] < time() - rand(1,10)))
 104          {
 105              $this->config->set('rand_seed_last_update', time(), true);
 106              $this->config->set('rand_seed', $this->config['rand_seed'], true);
 107              $dss_seeded = true;
 108          }
 109   
 110          return substr($val, 4, 16);
 111      }
 112   
 113      /**
 114      * Get random salt with specified length
 115      *
 116      * @param int $length Salt length
 117      * @param string $rand_seed Seed for random data (optional). For tests.
 118      *
 119      * @return string Random salt with specified length
 120      */
 121      public function get_random_salt($length, $rand_seed = '/dev/urandom')
 122      {
 123          $random = '';
 124   
 125          if (($fh = @fopen($rand_seed, 'rb')))
 126          {
 127              $random = fread($fh, $length);
 128              fclose($fh);
 129          }
 130   
 131          if (strlen($random) < $length)
 132          {
 133              $random = '';
 134              $random_state = $this->unique_id();
 135   
 136              for ($i = 0; $i < $length; $i += 16)
 137              {
 138                  $random_state = md5($this->unique_id() . $random_state);
 139                  $random .= pack('H*', md5($random_state));
 140              }
 141              $random = substr($random, 0, $length);
 142          }
 143          return $random;
 144      }
 145   
 146      /**
 147       * Compare two strings byte by byte
 148       *
 149       * @param string $string_a The first string
 150       * @param string $string_b The second string
 151       *
 152       * @return bool True if strings are the same, false if not
 153       */
 154      public function string_compare($string_a, $string_b)
 155      {
 156          $difference = strlen($string_a) != strlen($string_b);
 157   
 158          for ($i = 0; $i < strlen($string_a) && $i < strlen($string_b); $i++)
 159          {
 160              $difference |= $string_a[$i] != $string_b[$i];
 161          }
 162   
 163          return $difference === 0;
 164      }
 165  }
 166