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

Commit 529f4d2

Browse files
committed
Handle the password field having a value of null
1 parent 358795c commit 529f4d2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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: 21 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,24 @@ public function testAuthenticateWithNoIdentityParam()
222223
$this->expectException(InvalidConfigException::class);
223224
$user = $pdoDatabase->authenticate('test', 'password');
224225
}
226+
227+
public function testHandlesNullPassword()
228+
{
229+
$stmt = $this->prophesize(PDOStatement::class);
230+
$stmt->bindParam(Argument::any(), Argument::any())->willReturn();
231+
$stmt->execute(Argument::any())->willReturn();
232+
$stmt->fetchObject()->willReturn((object)['password' => null]);
233+
234+
$pdo = $this->prophesize(PDO::class);
235+
$pdo->prepare(Argument::any())->willReturn($stmt->reveal());
236+
237+
$pdoDatabase = new PdoDatabase(
238+
$pdo->reveal(),
239+
$this->getConfig(),
240+
$this->userFactory
241+
);
242+
243+
$user = $pdoDatabase->authenticate('null', null);
244+
$this->assertNull($user);
245+
}
225246
}

0 commit comments

Comments
 (0)