Index: branches/5.2.x/core/install/upgrades.php =================================================================== diff -u -N -r15450 -r15590 --- branches/5.2.x/core/install/upgrades.php (.../upgrades.php) (revision 15450) +++ branches/5.2.x/core/install/upgrades.php (.../upgrades.php) (revision 15590) @@ -1,6 +1,6 @@ Conn->Query('ALTER TABLE ' . $table_name . ' DROP RunInterval'); } + + /** + * Update to 5.2.1-B1 + * + * @param string $mode when called mode {before, after) + */ + public function Upgrade_5_2_1_B1($mode) + { + if ( $mode != 'after' ) { + return; + } + + $this->_updateUserPasswords(); + } + + protected function _updateUserPasswords() + { + $user_table = $this->Application->getUnitOption('u', 'TableName'); + + $sql = 'SELECT Password, PortalUserId + FROM ' . $user_table . ' + WHERE PasswordHashingMethod = ' . PasswordHashingMethod::MD5; + $user_passwords = $this->Conn->GetColIterator($sql, 'PortalUserId'); + + if ( !count($user_passwords) ) { + // no users at all or existing users have converted passwords already + return; + } + + kUtil::setResourceLimit(); + + $password_formatter = $this->Application->recallObject('kPasswordFormatter'); + /* @var $password_formatter kPasswordFormatter */ + + foreach ($user_passwords as $user_id => $user_password) { + $fields_hash = Array ( + 'Password' => $password_formatter->hashPassword($user_password, '', PasswordHashingMethod::MD5_AND_PHPPASS), + 'PasswordHashingMethod' => PasswordHashingMethod::MD5_AND_PHPPASS, + ); + + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'Users', 'PortalUserId = ' . $user_id); + } + } } \ No newline at end of file