diff --git a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php index e37b4a70c..f1079b7ac 100644 --- a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php @@ -1,7 +1,5 @@ data($model . '.' . $field); - if (empty($value) && $value !== "0" || !is_string($value)) { + if (empty($value) && $value !== '0' || !is_string($value)) { return false; } } diff --git a/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php b/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php index 90f5797c9..a8a17b2b8 100644 --- a/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php +++ b/lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php @@ -1,7 +1,5 @@ assertFalse($this->auth->authenticate($request, $this->response)); + $request->data = array( + 'User' => array( + 'user' => array(), + 'password' => 'my password' + )); + $this->assertFalse($this->auth->authenticate($request, $this->response)); + $request->data = array( 'User' => array( 'user' => 'mariano', @@ -226,6 +231,30 @@ class FormAuthenticateTest extends CakeTestCase { $this->assertFalse($this->auth->authenticate($request, $this->response)); } +/** + * Test that username of 0 works. + * + * @return void + */ + public function testAuthenticateUsernameZero() { + $User = ClassRegistry::init('User'); + $User->updateAll(array('user' => $User->getDataSource()->value('0')), array('user' => 'mariano')); + + $request = new CakeRequest('posts/index', false); + $request->data = array('User' => array( + 'user' => '0', + 'password' => 'password' + )); + + $expected = array( + 'id' => 1, + 'user' => '0', + 'created' => '2007-03-17 01:16:23', + 'updated' => '2007-03-17 01:18:31' + ); + $this->assertEquals($expected, $this->auth->authenticate($request, $this->response)); + } + /** * test a model in a plugin. *