Skip to content

Commit c1d40d3

Browse files
committed
[PasswordHasher] Fix missing PasswordHasherAwareInterface allowed type in signatures
1 parent e086194 commit c1d40d3

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

src/Symfony/Component/PasswordHasher/Hasher/PasswordHasherFactoryInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
1515
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
16-
use Symfony\Component\Security\Core\User\UserInterface;
1716

1817
/**
1918
* PasswordHasherFactoryInterface to support different password hashers for different user accounts.
@@ -26,7 +25,7 @@ interface PasswordHasherFactoryInterface
2625
/**
2726
* Returns the password hasher to use for the given user.
2827
*
29-
* @param PasswordAuthenticatedUserInterface|UserInterface|string $user A PasswordAuthenticatedUserInterface/UserInterface instance or a class name
28+
* @param PasswordHasherAwareInterface|PasswordAuthenticatedUserInterface|string $user A PasswordAuthenticatedUserInterface/PasswordHasherAwareInterface instance or a class name
3029
*
3130
* @throws \RuntimeException When no password hasher could be found for the user
3231
*/

src/Symfony/Component/PasswordHasher/Hasher/UserPasswordHasher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(PasswordHasherFactoryInterface $hasherFactory)
3232
}
3333

3434
/**
35-
* @param PasswordAuthenticatedUserInterface $user
35+
* @param PasswordAuthenticatedUserInterface|PasswordHasherAwareInterface $user
3636
*/
3737
public function hashPassword($user, string $plainPassword): string
3838
{
@@ -54,7 +54,7 @@ public function hashPassword($user, string $plainPassword): string
5454
}
5555

5656
/**
57-
* @param PasswordAuthenticatedUserInterface $user
57+
* @param PasswordAuthenticatedUserInterface|PasswordHasherAwareInterface $user
5858
*/
5959
public function isPasswordValid($user, string $plainPassword): bool
6060
{
@@ -80,7 +80,7 @@ public function isPasswordValid($user, string $plainPassword): bool
8080
}
8181

8282
/**
83-
* @param PasswordAuthenticatedUserInterface $user
83+
* @param PasswordAuthenticatedUserInterface|PasswordHasherAwareInterface $user
8484
*/
8585
public function needsRehash($user): bool
8686
{

src/Symfony/Component/PasswordHasher/Hasher/UserPasswordHasherInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
*
1919
* @author Ariel Ferrandini <arielferrandini@gmail.com>
2020
*
21-
* @method string hashPassword(PasswordAuthenticatedUserInterface $user, string $plainPassword) Hashes the plain password for the given user.
22-
* @method bool isPasswordValid(PasswordAuthenticatedUserInterface $user, string $plainPassword) Checks if the plaintext password matches the user's password.
23-
* @method bool needsRehash(PasswordAuthenticatedUserInterface $user) Checks if an encoded password would benefit from rehashing.
21+
* @method string hashPassword(PasswordAuthenticatedUserInterface|PasswordHasherAwareInterface $user, string $plainPassword) Hashes the plain password for the given user.
22+
* @method bool isPasswordValid(PasswordAuthenticatedUserInterface|PasswordHasherAwareInterface $user, string $plainPassword) Checks if the plaintext password matches the user's password.
23+
* @method bool needsRehash(PasswordAuthenticatedUserInterface|PasswordHasherAwareInterface $user) Checks if an encoded password would benefit from rehashing.
2424
*/
2525
interface UserPasswordHasherInterface
2626
{

src/Symfony/Component/PasswordHasher/Tests/Hasher/PasswordHasherFactoryTest.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
2222
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
2323
use Symfony\Component\Security\Core\User\InMemoryUser;
24-
use Symfony\Component\Security\Core\User\UserInterface;
24+
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
2525

2626
class PasswordHasherFactoryTest extends TestCase
2727
{
2828
public function testGetHasherWithMessageDigestHasher()
2929
{
30-
$factory = new PasswordHasherFactory([UserInterface::class => [
30+
$factory = new PasswordHasherFactory([PasswordAuthenticatedUserInterface::class => [
3131
'class' => MessageDigestPasswordHasher::class,
3232
'arguments' => ['sha512', true, 5],
3333
]]);
3434

35-
$hasher = $factory->getPasswordHasher($this->createMock(UserInterface::class));
35+
$hasher = $factory->getPasswordHasher($this->createMock(PasswordAuthenticatedUserInterface::class));
3636
$expectedHasher = new MessageDigestPasswordHasher('sha512', true, 5);
3737

3838
$this->assertEquals($expectedHasher->hash('foo', 'moo'), $hasher->hash('foo', 'moo'));
@@ -41,22 +41,18 @@ public function testGetHasherWithMessageDigestHasher()
4141
public function testGetHasherWithService()
4242
{
4343
$factory = new PasswordHasherFactory([
44-
UserInterface::class => new MessageDigestPasswordHasher('sha1'),
44+
PasswordAuthenticatedUserInterface::class => new MessageDigestPasswordHasher('sha1'),
4545
]);
4646

47-
$hasher = $factory->getPasswordHasher($this->createMock(UserInterface::class));
48-
$expectedHasher = new MessageDigestPasswordHasher('sha1');
49-
$this->assertEquals($expectedHasher->hash('foo', ''), $hasher->hash('foo', ''));
50-
51-
$hasher = $factory->getPasswordHasher(new InMemoryUser('user', 'pass'));
47+
$hasher = $factory->getPasswordHasher($this->createMock(PasswordAuthenticatedUserInterface::class));
5248
$expectedHasher = new MessageDigestPasswordHasher('sha1');
5349
$this->assertEquals($expectedHasher->hash('foo', ''), $hasher->hash('foo', ''));
5450
}
5551

5652
public function testGetHasherWithClassName()
5753
{
5854
$factory = new PasswordHasherFactory([
59-
UserInterface::class => new MessageDigestPasswordHasher('sha1'),
55+
PasswordAuthenticatedUserInterface::class => new MessageDigestPasswordHasher('sha1'),
6056
]);
6157

6258
$hasher = $factory->getPasswordHasher(SomeChildUser::class);
@@ -208,7 +204,7 @@ public function testLegacyEncoderClass()
208204
}
209205
}
210206

211-
class SomeUser implements UserInterface
207+
class SomeUser implements PasswordAuthenticatedUserInterface
212208
{
213209
public function getRoles(): array
214210
{

0 commit comments

Comments
 (0)