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

bcrypt.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 1.92 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 bcrypt extends base
017  {
018      const PREFIX = '$2a$';
019   
020      /**
021      * {@inheritdoc}
022      */
023      public function get_prefix()
024      {
025          return self::PREFIX;
026      }
027   
028      /**
029      * {@inheritdoc}
030      */
031      public function hash($password, $salt = '')
032      {
033          // The 2x and 2y prefixes of bcrypt might not be supported
034          // Revert to 2a if this is the case
035          $prefix = (!$this->is_supported()) ? '$2a$' : $this->get_prefix();
036   
037          // Do not support 8-bit characters with $2a$ bcrypt
038          // Also see http://www.php.net/security/crypt_blowfish.php
039          if ($prefix === self::PREFIX)
040          {
041              if (ord($password[strlen($password)-1]) & 128)
042              {
043                  return false;
044              }
045          }
046   
047          if ($salt == '')
048          {
049              $salt = $prefix . '10$' . $this->get_random_salt();
050          }
051   
052          $hash = crypt($password, $salt);
053          if (strlen($hash) < 60)
054          {
055              return false;
056          }
057          return $hash;
058      }
059   
060      /**
061      * {@inheritdoc}
062      */
063      public function check($password, $hash, $user_row = array())
064      {
065          $salt = substr($hash, 0, 29);
066          if (strlen($salt) != 29)
067          {
068              return false;
069          }
070   
071          if ($this->helper->string_compare($hash, $this->hash($password, $salt)))
072          {
073              return true;
074          }
075          return false;
076      }
077   
078      /**
079      * Get a random salt value with a length of 22 characters
080      *
081      * @return string Salt for password hashing
082      */
083      protected function get_random_salt()
084      {
085          return $this->helper->hash_encode64($this->helper->get_random_salt(22), 22);
086      }
087   
088      /**
089      * {@inheritdoc}
090      */
091      public function get_settings_only($hash, $full = false)
092      {
093          if ($full)
094          {
095              $pos = stripos($hash, '$', 1) + 1;
096              $length = 22 + (strripos($hash, '$') + 1 - $pos);
097          }
098          else
099          {
100              $pos = strripos($hash, '$') + 1;
101              $length = 22;
102          }
103          return substr($hash, $pos, $length);
104      }
105  }
106