Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 6545ec1

Browse files
committed
Merge branch 'jonsa-bugfix/handle_null_password'
2 parents 358795c + 7d47fef commit 6545ec1

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#37](https://github.com/zendframework/zend-expressive-authentication/pull/37) handles null values when verifying password in `PdoDatabase`
2626

2727
## 1.0.0 - 2018-08-27
2828

src/UserRepository/PdoDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function authenticate(string $credential, string $password = null) : ?Use
8282
return null;
8383
}
8484

85-
if (password_verify($password, $result->{$this->config['field']['password']})) {
85+
if (password_verify($password ?? '', $result->{$this->config['field']['password']} ?? '')) {
8686
return ($this->userFactory)(
8787
$credential,
8888
$this->getUserRoles($credential),

test/UserRepository/PdoDatabaseTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace ZendTest\Expressive\Authentication\UserRepository;
1111

1212
use PDO;
13+
use PDOStatement;
1314
use PHPUnit\Framework\TestCase;
1415
use Prophecy\Argument;
1516
use Zend\Expressive\Authentication\DefaultUser;
@@ -222,4 +223,35 @@ public function testAuthenticateWithNoIdentityParam()
222223
$this->expectException(InvalidConfigException::class);
223224
$user = $pdoDatabase->authenticate('test', 'password');
224225
}
226+
227+
public function getVoidPasswords()
228+
{
229+
return [
230+
[ null ],
231+
[ '' ]
232+
];
233+
}
234+
235+
/**
236+
* @dataProvider getVoidPasswords
237+
*/
238+
public function testHandlesNullOrEmptyPassword($password)
239+
{
240+
$stmt = $this->prophesize(PDOStatement::class);
241+
$stmt->bindParam(Argument::any(), Argument::any())->willReturn();
242+
$stmt->execute(Argument::any())->willReturn();
243+
$stmt->fetchObject()->willReturn((object)['password' => $password]);
244+
245+
$pdo = $this->prophesize(PDO::class);
246+
$pdo->prepare(Argument::any())->willReturn($stmt->reveal());
247+
248+
$pdoDatabase = new PdoDatabase(
249+
$pdo->reveal(),
250+
$this->getConfig(),
251+
$this->userFactory
252+
);
253+
254+
$user = $pdoDatabase->authenticate('null', $password);
255+
$this->assertNull($user);
256+
}
225257
}

0 commit comments

Comments
 (0)