Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed issue: No way to reset a forgotten password
  • Loading branch information
c-schmitz committed Apr 24, 2013
1 parent 6bf206e commit 2017a69
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
34 changes: 34 additions & 0 deletions application/commands/ResetPasswordCommand.php
@@ -0,0 +1,34 @@
<?php
/*
* LimeSurvey (tm)
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/
class ResetPasswordCommand extends CConsoleCommand
{
public $connection;

public function run($sArgument)
{
if (!isset($sArgument) || !isset($sArgument[0]) || !isset($sArgument[1])) die('You have to set username and password on the command line like this: php console.php username password');
$iUserID=User::model()->getID($sArgument[0]);
if ($iUserID)
{
User::model()->updatePassword($iUserID,$sArgument[1]);
echo "Password for user {$sArgument[0]} was set.\n";
}
else
{
echo "User {$sArgument[0]} not found.\n";
}
}
}

?>
2 changes: 1 addition & 1 deletion application/controllers/admin/authentication.php
Expand Up @@ -138,7 +138,7 @@ private function _sendPasswordEmail($sEmailAddr, $aFields)

if (SendEmailMessage($body, $sSubject, $sTo, $sFrom, $sSiteName, false, $sSiteAdminBounce))
{
User::model()->updatePassword($aFields[0]['uid'], hash('sha256', $sNewPass));
User::model()->updatePassword($aFields[0]['uid'], $sNewPass);
$sMessage = $username . '<br />' . $email . '<br /><br />' . $clang->gT('An email with your login data was sent to you.');
}
else
Expand Down
21 changes: 10 additions & 11 deletions application/models/User.php
Expand Up @@ -244,22 +244,21 @@ public function getuidfromparentid($parentid)
*/
public function getID($fullname)
{
$this->db->select('uid');
$this->db->from('users');
$this->db->where(array("full_name"=>Yii::app()->db->quoteValue($fullname)));
$result = $this->db->get();
return $result->row();
return $this->db->createCommand()->select('uid')
->from('users')
->where(array("full_name"=>Yii::app()->db->quoteValue($fullname)))
->queryScalar();
}

/**
* Updates user password
*
* @access public
* @return string
* Updates user password hash
*
* @param int $uid The User ID
* @param string $sPassword The clear text password
*/
public function updatePassword($uid,$password)
public function updatePassword($uid, $sPassword)
{
return $this->updateByPk($uid, array('password' => $password));
return $this->updateByPk($uid, array('password' => hash('sha256', $sPassword)));
}

/**
Expand Down

0 comments on commit 2017a69

Please sign in to comment.