Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
salted_md5.php
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 /**
017 *
018 * @version Version 0.1 / slightly modified for phpBB 3.1.x (using $H$ as hash type identifier)
019 *
020 * Portable PHP password hashing framework.
021 *
022 * Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in
023 * the public domain.
024 *
025 * There's absolutely no warranty.
026 *
027 * The homepage URL for this framework is:
028 *
029 * http://www.openwall.com/phpass/
030 *
031 * Please be sure to update the Version line if you edit this file in any way.
032 * It is suggested that you leave the main version number intact, but indicate
033 * your project name (after the slash) and add your own revision information.
034 *
035 * Please do not change the "private" password hashing method implemented in
036 * here, thereby making your hashes incompatible. However, if you must, please
037 * change the hash type identifier (the "$P$") to something different.
038 *
039 * Obviously, since this code is in the public domain, the above are not
040 * requirements (there can be none), but merely suggestions.
041 *
042 */
043
044 class salted_md5 extends base
045 {
046 const PREFIX = '$H$';
047
048 /**
049 * {@inheritdoc}
050 */
051 public function get_prefix()
052 {
053 return self::PREFIX;
054 }
055
056 /**
057 * {@inheritdoc}
058 */
059 public function is_legacy()
060 {
061 return true;
062 }
063
064 /**
065 * {@inheritdoc}
066 */
067 public function hash($password, $setting = '')
068 {
069 if ($setting)
070 {
071 if (($settings = $this->get_hash_settings($setting)) === false)
072 {
073 // Return md5 of password if settings do not
074 // comply with our standards. This will only
075 // happen if pre-determined settings are
076 // directly passed to the driver. The manager
077 // will not do this. Same as the old hashing
078 // implementation in phpBB 3.0
079 return md5($password);
080 }
081 }
082 else
083 {
084 $settings = $this->get_hash_settings($this->generate_salt());
085 }
086
087 $hash = md5($settings['salt'] . $password, true);
088 do
089 {
090 $hash = md5($hash . $password, true);
091 }
092 while (--$settings['count']);
093
094 $output = $settings['full'];
095 $output .= $this->helper->hash_encode64($hash, 16);
096
097 return $output;
098 }
099
100 /**
101 * {@inheritdoc}
102 */
103 public function check($password, $hash, $user_row = array())
104 {
105 if (strlen($hash) !== 34)
106 {
107 return md5($password) === $hash;
108 }
109
110 return $this->helper->string_compare($hash, $this->hash($password, $hash));
111 }
112
113 /**
114 * Generate salt for hashing method
115 *
116 * @return string Salt for hashing method
117 */
118 protected function generate_salt()
119 {
120 $count = 6;
121
122 $random = $this->helper->get_random_salt($count);
123
124 $salt = $this->get_prefix();
125 $salt .= $this->helper->itoa64[min($count + 5, 30)];
126 $salt .= $this->helper->hash_encode64($random, $count);
127
128 return $salt;
129 }
130
131 /**
132 * Get hash settings
133 *
134 * @param string $hash The hash that contains the settings
135 *
136 * @return bool|array Array containing the count_log2, salt, and full
137 * hash settings string or false if supplied hash is empty
138 * or contains incorrect settings
139 */
140 public function get_hash_settings($hash)
141 {
142 if (empty($hash))
143 {
144 return false;
145 }
146
147 $count_log2 = strpos($this->helper->itoa64, $hash[3]);
148 $salt = substr($hash, 4, 8);
149
150 if ($count_log2 < 7 || $count_log2 > 30 || strlen($salt) != 8)
151 {
152 return false;
153 }
154
155 return array(
156 'count' => 1 << $count_log2,
157 'salt' => $salt,
158 'full' => substr($hash, 0, 12),
159 );
160 }
161
162 /**
163 * {@inheritdoc}
164 */
165 public function get_settings_only($hash, $full = false)
166 {
167 return substr($hash, 3, 9);
168 }
169 }
170