Skip to content

Commit c70b102

Browse files
Stefan Kruppafabpot
Stefan Kruppa
authored andcommitted
Fail on empty password verification (without warning on any implementation)
1 parent d2550b4 commit c70b102

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

Encoder/NativePasswordEncoder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function encodePassword($raw, $salt): string
7676
*/
7777
public function isPasswordValid($encoded, $raw, $salt): bool
7878
{
79+
if ('' === $raw) {
80+
return false;
81+
}
7982
if (\strlen($raw) > self::MAX_PASSWORD_LENGTH) {
8083
return false;
8184
}

Encoder/SodiumPasswordEncoder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function encodePassword($raw, $salt): string
7676
*/
7777
public function isPasswordValid($encoded, $raw, $salt): bool
7878
{
79+
if ('' === $raw) {
80+
return false;
81+
}
7982
if (\strlen($raw) > self::MAX_PASSWORD_LENGTH) {
8083
return false;
8184
}

Tests/Encoder/NativePasswordEncoderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function testValidation()
5353
$result = $encoder->encodePassword('password', null);
5454
$this->assertTrue($encoder->isPasswordValid($result, 'password', null));
5555
$this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null));
56+
$this->assertFalse($encoder->isPasswordValid($result, '', null));
5657
}
5758

5859
public function testNonArgonValidation()

Tests/Encoder/SodiumPasswordEncoderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function testValidation()
2929
$result = $encoder->encodePassword('password', null);
3030
$this->assertTrue($encoder->isPasswordValid($result, 'password', null));
3131
$this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null));
32+
$this->assertFalse($encoder->isPasswordValid($result, '', null));
3233
}
3334

3435
public function testBCryptValidation()

0 commit comments

Comments
 (0)