Skip to content

Commit

Permalink
updating auth component and test with additional checks for missing data
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7979 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
gwoo committed Jan 14, 2009
1 parent 4a636b9 commit e496fc9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
34 changes: 20 additions & 14 deletions cake/libs/controller/components/auth.php
Expand Up @@ -297,23 +297,29 @@ function startup(&$controller) {
} }
return false; return false;
} }
$username = $controller->data[$this->userModel][$this->fields['username']];
$password = $controller->data[$this->userModel][$this->fields['password']];


$data = array( $isValid = !empty($controller->data[$this->userModel][$this->fields['username']]) &&
$this->userModel . '.' . $this->fields['username'] => $username, !empty($controller->data[$this->userModel][$this->fields['password']]);
$this->userModel . '.' . $this->fields['password'] => $password
);


if ($this->login($data)) { if ($isValid) {
if ($this->autoRedirect) { $username = $controller->data[$this->userModel][$this->fields['username']];
$controller->redirect($this->redirect(), null, true); $password = $controller->data[$this->userModel][$this->fields['password']];

$data = array(
$this->userModel . '.' . $this->fields['username'] => $username,
$this->userModel . '.' . $this->fields['password'] => $password
);

if ($this->login($data)) {
if ($this->autoRedirect) {
$controller->redirect($this->redirect(), null, true);
}
return true;
} }
return true;
} else {
$this->Session->setFlash($this->loginError, 'default', array(), 'auth');
$controller->data[$this->userModel][$this->fields['password']] = null;
} }

$this->Session->setFlash($this->loginError, 'default', array(), 'auth');
$controller->data[$this->userModel][$this->fields['password']] = null;
return false; return false;
} else { } else {
if (!$this->user()) { if (!$this->user()) {
Expand Down Expand Up @@ -794,7 +800,7 @@ function identify($user = null, $conditions = null) {
if (empty($data) || empty($data[$this->userModel])) { if (empty($data) || empty($data[$this->userModel])) {
return null; return null;
} }
} elseif (!empty($user)) { } elseif (!empty($user) && is_string($user)) {
$model =& $this->getModel(); $model =& $this->getModel();
$data = $model->find(array_merge(array($model->escapeField() => $user), $conditions)); $data = $model->find(array_merge(array($model->escapeField() => $user), $conditions));


Expand Down
15 changes: 14 additions & 1 deletion cake/tests/cases/libs/controller/components/auth.test.php
Expand Up @@ -822,7 +822,6 @@ function testEmptyUsernameOrPassword() {
*/ */
function testInjection() { function testInjection() {
$this->AuthUser =& new AuthUser(); $this->AuthUser =& new AuthUser();
Configure::write('debug', 1);
$this->AuthUser->id = 2; $this->AuthUser->id = 2;
$this->AuthUser->saveField('password', Security::hash(Configure::read('Security.salt') . 'cake')); $this->AuthUser->saveField('password', Security::hash(Configure::read('Security.salt') . 'cake'));


Expand Down Expand Up @@ -856,6 +855,20 @@ function testInjection() {


$this->Controller->Auth->startup($this->Controller); $this->Controller->Auth->startup($this->Controller);
$this->assertTrue(is_null($this->Controller->Auth->user())); $this->assertTrue(is_null($this->Controller->Auth->user()));

unset($this->Controller->data['AuthUser']['password']);
$this->Controller->data['AuthUser']['username'] = "1'1";
$this->Controller->Auth->initialize($this->Controller);

$this->Controller->Auth->startup($this->Controller);
$this->assertTrue(is_null($this->Controller->Auth->user()));

unset($this->Controller->data['AuthUser']['username']);
$this->Controller->data['AuthUser']['password'] = "1'1";
$this->Controller->Auth->initialize($this->Controller);

$this->Controller->Auth->startup($this->Controller);
$this->assertTrue(is_null($this->Controller->Auth->user()));
} }
/** /**
* test Hashing of passwords * test Hashing of passwords
Expand Down

0 comments on commit e496fc9

Please sign in to comment.