Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpgradePasswordHashes.php
Go to the documentation of this file.
1 <?php
8 
13 
19 {
23  private $moduleDataSetup;
24 
29  public function __construct(
30  \Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup
31  ) {
32  $this->moduleDataSetup = $moduleDataSetup;
33  }
34 
38  public function apply()
39  {
40  $this->moduleDataSetup->getConnection()->startSetup();
41  $this->upgradeHash();
42  $this->moduleDataSetup->getConnection()->endSetup();
43  }
44 
48  public static function getDependencies()
49  {
50  return [];
51  }
52 
56  public static function getVersion()
57  {
58  return '2.0.1';
59  }
60 
64  public function getAliases()
65  {
66  return [];
67  }
68 
72  private function upgradeHash()
73  {
74  $connection = $this->moduleDataSetup->getConnection();
75  $customerEntityTable = $this->moduleDataSetup->getTable('admin_user');
76 
77  $select = $connection->select()->from(
78  $customerEntityTable,
79  ['user_id', 'password']
80  );
81 
82  $customers = $connection->fetchAll($select);
83  foreach ($customers as $customer) {
84  list($hash, $salt) = explode(Encryptor::DELIMITER, $customer['password']);
85 
86  $newHash = $customer['password'];
87  if (strlen($hash) === 32) {
88  $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_MD5]);
89  } elseif (strlen($hash) === 64) {
90  $newHash = implode(Encryptor::DELIMITER, [$hash, $salt, Encryptor::HASH_VERSION_SHA256]);
91  }
92 
93  $bind = ['password' => $newHash];
94  $where = ['user_id = ?' => (int)$customer['user_id']];
95  $connection->update($customerEntityTable, $bind, $where);
96  }
97  }
98 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$customer
Definition: customers.php:11
$connection
Definition: bulk.php:13
__construct(\Magento\Framework\Setup\ModuleDataSetupInterface $moduleDataSetup)