diff --git a/cake/libs/controller/components/auth.php b/cake/libs/controller/components/auth.php index 07e4c918e..e5af3ad53 100644 --- a/cake/libs/controller/components/auth.php +++ b/cake/libs/controller/components/auth.php @@ -293,8 +293,8 @@ class AuthComponent extends Object { } $data = array( - $this->userModel . '.' . $this->fields['username'] => '= ' . $controller->data[$this->userModel][$this->fields['username']], - $this->userModel . '.' . $this->fields['password'] => '= ' . $controller->data[$this->userModel][$this->fields['password']] + $this->userModel . '.' . $this->fields['username'] => $controller->data[$this->userModel][$this->fields['username']], + $this->userModel . '.' . $this->fields['password'] => $controller->data[$this->userModel][$this->fields['password']] ); if ($this->login($data)) { @@ -722,8 +722,12 @@ class AuthComponent extends Object { } elseif (is_array($user) && isset($user[$this->userModel])) { $user = $user[$this->userModel]; } - + $debug = false; + if ($debug = Configure::read('debug')) { + Configure::write('debug', 0); + } if (is_array($user) && (isset($user[$this->fields['username']]) || isset($user[$this->userModel . '.' . $this->fields['username']]))) { + if (isset($user[$this->fields['username']]) && !empty($user[$this->fields['username']]) && !empty($user[$this->fields['password']])) { if (trim($user[$this->fields['username']]) == '=' || trim($user[$this->fields['password']]) == '=') { return false; @@ -756,6 +760,9 @@ class AuthComponent extends Object { return null; } } + if ($debug) { + Configure::write('debug', $debug); + } if (isset($data) && !empty($data)) { if (!empty($data[$this->userModel][$this->fields['password']])) { unset($data[$this->userModel][$this->fields['password']]); diff --git a/cake/tests/cases/libs/controller/components/auth.test.php b/cake/tests/cases/libs/controller/components/auth.test.php index 1607cd179..b77771795 100644 --- a/cake/tests/cases/libs/controller/components/auth.test.php +++ b/cake/tests/cases/libs/controller/components/auth.test.php @@ -161,6 +161,34 @@ class AuthTest extends CakeTestCase { $user = $this->Controller->Auth->user(); $this->assertEqual($user, array('AuthUser'=>array('id'=>1, 'username'=>'mariano', 'created'=> '2007-03-17 01:16:23', 'updated'=> date('Y-m-d H:i:s')))); $this->Controller->Session->del('Auth'); + + $this->Controller->data['AuthUser']['username'] = 'blah'; + $this->Controller->data['AuthUser']['password'] = ''; + + $this->Controller->Auth->startup($this->Controller); + + $user = $this->Controller->Auth->user(); + $this->assertFalse($user); + $this->Controller->Session->del('Auth'); + + $this->Controller->data['AuthUser']['username'] = 'now() or 1=1 --'; + $this->Controller->data['AuthUser']['password'] = ''; + + $this->Controller->Auth->startup($this->Controller); + + $user = $this->Controller->Auth->user(); + $this->assertFalse($user); + $this->Controller->Session->del('Auth'); + + $this->Controller->data['AuthUser']['username'] = 'now() or 1=1 # something'; + $this->Controller->data['AuthUser']['password'] = ''; + + $this->Controller->Auth->startup($this->Controller); + + $user = $this->Controller->Auth->user(); + $this->assertFalse($user); + $this->Controller->Session->del('Auth'); + } function testAuthorizeFalse() {