Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
update_hashes.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 namespace phpbb\console\command\fixup;
014
015 use Symfony\Component\Console\Input\InputInterface;
016 use Symfony\Component\Console\Output\OutputInterface;
017 use Symfony\Component\Console\Helper\ProgressBar;
018
019 class update_hashes extends \phpbb\console\command\command
020 {
021 /** @var \phpbb\config\config */
022 protected $config;
023
024 /** @var \phpbb\db\driver\driver_interface */
025 protected $db;
026
027 /** @var \phpbb\passwords\manager */
028 protected $passwords_manager;
029
030 /** @var string Default hashing type */
031 protected $default_type;
032
033 /**
034 * Update_hashes constructor
035 *
036 * @param \phpbb\config\config $config
037 * @param \phpbb\user $user
038 * @param \phpbb\db\driver\driver_interface $db
039 * @param \phpbb\passwords\manager $passwords_manager
040 * @param array $hashing_algorithms Hashing driver
041 * service collection
042 * @param array $defaults Default password types
043 */
044 public function __construct(\phpbb\config\config $config, \phpbb\user $user,
045 \phpbb\db\driver\driver_interface $db, \phpbb\passwords\manager $passwords_manager,
046 $hashing_algorithms, $defaults)
047 {
048 $this->config = $config;
049 $this->db = $db;
050
051 $this->passwords_manager = $passwords_manager;
052
053 foreach ($defaults as $type)
054 {
055 if ($hashing_algorithms[$type]->is_supported())
056 {
057 $this->default_type = $type;
058 break;
059 }
060 }
061
062 parent::__construct($user);
063 }
064
065 /**
066 * {@inheritdoc}
067 */
068 protected function configure()
069 {
070 $this
071 ->setName('fixup:update-hashes')
072 ->setDescription($this->user->lang('CLI_DESCRIPTION_UPDATE_HASH_BCRYPT'))
073 ;
074 }
075
076 /**
077 * {@inheritdoc}
078 */
079 protected function execute(InputInterface $input, OutputInterface $output)
080 {
081 // Get count to be able to display progress
082 $sql = 'SELECT COUNT(user_id) AS count
083 FROM ' . USERS_TABLE . '
084 WHERE user_password ' . $this->db->sql_like_expression('$H$' . $this->db->get_any_char()) . '
085 OR user_password ' . $this->db->sql_like_expression('$CP$' . $this->db->get_any_char());
086 $result = $this->db->sql_query($sql);
087 $total_update_passwords = $this->db->sql_fetchfield('count');
088 $this->db->sql_freeresult($result);
089
090 // Create progress bar
091 $progress_bar = new ProgressBar($output, $total_update_passwords);
092 $progress_bar->start();
093
094 $sql = 'SELECT user_id, user_password
095 FROM ' . USERS_TABLE . '
096 WHERE user_password ' . $this->db->sql_like_expression('$H$' . $this->db->get_any_char()) . '
097 OR user_password ' . $this->db->sql_like_expression('$CP$' . $this->db->get_any_char());
098 $result = $this->db->sql_query($sql);
099
100 while ($row = $this->db->sql_fetchrow($result))
101 {
102 $old_hash = preg_replace('/^\$CP\$/', '', $row['user_password']);
103
104 // If stored hash type is unknown then it's md5 hash with no prefix
105 // First rehash it using $H$ as hash type identifier (salted_md5)
106 if (!$this->passwords_manager->detect_algorithm($old_hash))
107 {
108 $old_hash = $this->passwords_manager->hash($old_hash, '$H$');
109 }
110
111 $new_hash = $this->passwords_manager->hash($old_hash, [$this->default_type]);
112
113 $sql = 'UPDATE ' . USERS_TABLE . "
114 SET user_password = '" . $this->db->sql_escape($new_hash) . "'
115 WHERE user_id = " . (int) $row['user_id'];
116 $this->db->sql_query($sql);
117 $progress_bar->advance();
118 }
119
120 $this->config->set('update_hashes_last_cron', time());
121
122 $progress_bar->finish();
123
124 $output->writeln('<info>' . $this->user->lang('CLI_FIXUP_UPDATE_HASH_BCRYPT_SUCCESS') . '</info>');
125 }
126 }
127