Skip to content

Commit

Permalink
Fixed edge case which allowed login with empty password.
Browse files Browse the repository at this point in the history
Ensure skipping call to FormAuthenticate::_checkFields() does not allow
logging in with empty password. Closes #2441.
  • Loading branch information
ADmad committed Dec 7, 2013
1 parent 85a9132 commit 738d0e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/Cake/Controller/Component/Auth/BaseAuthenticate.php
@@ -1,7 +1,5 @@
<?php
/**
*
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -118,7 +116,7 @@ protected function _findUser($username, $password = null) {
}

$user = $result[$model];
if ($password) {
if ($password !== null) {
if (!$this->passwordHasher()->check($password, $user[$fields['password']])) {
return false;
}
Expand Down
Expand Up @@ -118,6 +118,40 @@ public function testAuthenticatePasswordIsFalse() {
$this->assertFalse($this->auth->authenticate($request, $this->response));
}

/**
* Test for password as empty string with _checkFields() call skipped
* Refs https://github.com/cakephp/cakephp/pull/2441
*
* @return void
*/
public function testAuthenticatePasswordIsEmptyString() {
$request = new CakeRequest('posts/index', false);
$request->data = array(
'User' => array(
'user' => 'mariano',
'password' => ''
));

$this->auth = $this->getMock(
'FormAuthenticate',
array('_checkFields'),
array(
$this->Collection,
array(
'fields' => array('username' => 'user', 'password' => 'password'),
'userModel' => 'User'
)
)
);

// Simulate that check for ensuring password is not empty is missing.
$this->auth->expects($this->once())
->method('_checkFields')
->will($this->returnValue(true));

$this->assertFalse($this->auth->authenticate($request, $this->response));
}

/**
* test authenticate field is not string
*
Expand Down

0 comments on commit 738d0e2

Please sign in to comment.