Skip to content

Commit

Permalink
Fixed issue #6873: Administration login using one-time password not w…
Browse files Browse the repository at this point in the history
…orking
  • Loading branch information
c-schmitz committed Nov 15, 2012
1 parent 67da66a commit 3ec0a1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 6 additions & 5 deletions application/controllers/admin/authentication.php
Expand Up @@ -37,9 +37,10 @@ public function index()

if ($bCanLogin && !is_array($bCanLogin))
{
if (Yii::app()->request->getPost('action'))
if (Yii::app()->request->getPost('action') || !is_null(Yii::app()->request->getQuery('onepass')))
{
$aData = $this->_doLogin(Yii::app()->request->getPost('user'), Yii::app()->request->getPost('password'));

$aData = $this->_doLogin(Yii::app()->request->getParam('user'), Yii::app()->request->getPost('password'),Yii::app()->request->getQuery('onepass',''));

if (!isset($aData['errormsg']))
{
Expand Down Expand Up @@ -247,11 +248,11 @@ private function _doRedirect()
* @param string $sPassword The password to login with
* @return Array of data containing errors for the view
*/
private function _doLogin($sUsername, $sPassword)
private function _doLogin($sUsername, $sPassword, $sOneTimePassword)
{
$identity = new UserIdentity(sanitize_user($sUsername), $sPassword);

if (!$identity->authenticate())
if (!$identity->authenticate($sOneTimePassword))
{
return $this->_getAuthenticationFailedErrorMessage();
}
Expand Down Expand Up @@ -324,7 +325,7 @@ private function _checkForUsageOfDefaultPassword()
{
$clang = $this->getController()->lang;
Yii::app()->session['pw_notify'] = false;
if (strtolower($_POST['password']) === 'password')
if (strtolower(Yii::app()->request->getPost('password','') ) === 'password')
{
Yii::app()->session['pw_notify'] = true;
Yii::app()->session['flashmessage'] = $clang->gT('Warning: You are still using the default password (\'password\'). Please change your password and re-login again.');
Expand Down
17 changes: 14 additions & 3 deletions application/core/UserIdentity.php
Expand Up @@ -17,14 +17,15 @@ class UserIdentity extends CUserIdentity
{
protected $id;
protected $user;
protected $sOneTimePassword;

/**
* Checks whether this user has correctly entered password or not
*
* @access public
* @return bool
*/
public function authenticate()
public function authenticate($sOneTimePassword='')
{
if (Yii::app()->getConfig("auth_webserver")==false)
{
Expand All @@ -41,11 +42,21 @@ public function authenticate()
$sStoredPassword=$user->password;
}
}
if ($user === null)
else
{
$this->errorCode = self::ERROR_USERNAME_INVALID;
return !$this->errorCode;
}

if ($sOneTimePassword!='' && Yii::app()->getConfig("use_one_time_passwords") && md5($sOneTimePassword)==$user->one_time_pw)
{
$user->one_time_pw='';
$user->save();
$this->id = $user->uid;
$this->user = $user;
$this->errorCode = self::ERROR_NONE;
}
else if ($sStoredPassword !== hash('sha256', $this->password))
elseif ($sStoredPassword !== hash('sha256', $this->password))
{
$this->errorCode = self::ERROR_PASSWORD_INVALID;
}
Expand Down

0 comments on commit 3ec0a1f

Please sign in to comment.