mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixed edge case which allowed login with empty password.
Ensure skipping call to FormAuthenticate::_checkFields() does not allow logging in with empty password. Closes #2441.
This commit is contained in:
parent
85a9132c9b
commit
738d0e2277
2 changed files with 35 additions and 3 deletions
|
@ -1,7 +1,5 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
|
@ -118,7 +116,7 @@ abstract class BaseAuthenticate {
|
|||
}
|
||||
|
||||
$user = $result[$model];
|
||||
if ($password) {
|
||||
if ($password !== null) {
|
||||
if (!$this->passwordHasher()->check($password, $user[$fields['password']])) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -118,6 +118,40 @@ class FormAuthenticateTest extends CakeTestCase {
|
|||
$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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue