Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 990f53b

Browse files
committed
ENH: refs #952. Support upgrade process for 3.2.12
1 parent 8e83c33 commit 990f53b

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

core/AppController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public function preDispatch()
108108
if(count($tmp) == 2)
109109
{
110110
$userDao = $userModel->load($tmp[0]);
111-
if($userDao != false && $userModel->hashExists($tmp[1]))
111+
112+
if(version_compare(Zend_Registry::get('configDatabase')->version, '3.2.12', '>=') &&
113+
$userDao != false && $userModel->hashExists($tmp[1]))
112114
{
113115
$user->Dao = $userDao;
114116
}

core/controllers/UserController.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,20 @@ function loginAction()
466466
}
467467

468468
$instanceSalt = Zend_Registry::get('configGlobal')->password->prefix;
469-
$passwordHash = hash($userDao->getHashAlg(), $instanceSalt.$userDao->getSalt().$form->getValue('password'));
470-
if($authModule || $this->User->hashExists($passwordHash))
469+
$currentVersion = Zend_Registry::get('configDatabase')->version;
470+
// We have to have this so that an admin can log in to upgrade from version < 3.2.12 to >= 3.2.12.
471+
// Version 3.2.12 introduced the new password hashing and storage system.
472+
if(version_compare($currentVersion, '3.2.12', '>='))
473+
{
474+
$passwordHash = hash($userDao->getHashAlg(), $instanceSalt.$userDao->getSalt().$form->getValue('password'));
475+
$coreAuth = $this->User->hashExists($passwordHash);
476+
}
477+
else
478+
{
479+
$coreAuth = $this->User->legacyAuthenticate($userDao, $instanceSalt, $form->getValue('password'));
480+
}
481+
482+
if($authModule || $coreAuth)
471483
{
472484
$notifications = Zend_Registry::get('notifier')->callback('CALLBACK_CORE_AUTH_INTERCEPT', array('user' => $userDao));
473485
foreach($notifications as $module => $value)
@@ -478,7 +490,7 @@ function loginAction()
478490
return;
479491
}
480492
}
481-
if($userDao->getSalt() == '')
493+
if(version_compare($currentVersion, '3.2.12', '>=') && $userDao->getSalt() == '')
482494
{
483495
$passwordHash = $this->User->convertLegacyPasswordHash($userDao, $form->getValue('password'));
484496
}

core/models/base/UserModelBase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ abstract function getByFolder($folder);
7070
/** Returns all the users */
7171
abstract function getAll($onlyPublic = false, $limit = 20, $order = 'lastname', $offset = null, $currentUser = null);
7272
abstract function storePasswordHash($hash);
73+
abstract function legacyAuthenticate($userDao, $instanceSalt, $password);
7374

7475
/** save */
7576
public function save($dao)

core/models/pdo/UserModel.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,31 @@ function getUsersFromSearch($search, $userDao, $limit = 14, $group = true, $orde
305305
return $return;
306306
} // end getUsersFromSearch()
307307

308-
}// end class
308+
/**
309+
* Uses the pre-3.2.12 authentication mechanism. Only call this if the version
310+
* of the database is below 3.2.12, will throw DB exceptions otherwise.
311+
* NOTE: This may ONLY be used to authenticate site admins. This is meant to be
312+
* used during the upgrade process only, not for general authentication.
313+
* @return True or false: whether the authentication succeeded
314+
*/
315+
function legacyAuthenticate($userDao, $instanceSalt, $password)
316+
{
317+
$hash = md5($instanceSalt.$password);
318+
$sql = $this->database->select()->setIntegrityCheck(false)
319+
->where('user_id = ?', $userDao->getKey());
320+
321+
322+
$row = $this->database->fetchRow($sql);
323+
$pw = $row['password'];
324+
325+
if(!$pw)
326+
{
327+
throw new Zend_Exception('Tried to call legacyAuthenticate on 3.2.12+ schema');
328+
}
329+
if($row['admin'] != 1)
330+
{
331+
throw new Zend_Exception('Only admin users may use legacyAuthenticate');
332+
}
333+
return $pw === $hash;
334+
}
335+
}// end class

0 commit comments

Comments
 (0)