Skip to content

Commit b1815d6

Browse files
authored
Merge pull request #2863 from dunglas/use-passwordencoder
Switch to UserPasswordEncoder instead of password_verify
2 parents 08bb437 + f838ad2 commit b1815d6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

behat.yml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ default:
44
contexts:
55
- 'DoctrineContext':
66
doctrine: '@doctrine'
7+
passwordEncoder: '@security.password_encoder'
78
- 'HttpHeaderContext'
89
- 'GraphqlContext'
910
- 'JsonContext'
@@ -40,6 +41,7 @@ postgres:
4041
contexts:
4142
- 'DoctrineContext':
4243
doctrine: '@doctrine'
44+
passwordEncoder: '@security.password_encoder'
4345
- 'HttpHeaderContext'
4446
- 'GraphqlContext'
4547
- 'JsonContext'
@@ -63,6 +65,7 @@ mongodb:
6365
contexts:
6466
- 'DoctrineContext':
6567
doctrine: '@doctrine_mongodb'
68+
passwordEncoder: '@security.password_encoder'
6669
- 'HttpHeaderContext'
6770
- 'GraphqlContext'
6871
- 'JsonContext'
@@ -103,6 +106,7 @@ default-coverage:
103106
contexts:
104107
- 'DoctrineContext':
105108
doctrine: '@doctrine'
109+
passwordEncoder: '@security.password_encoder'
106110
- 'HttpHeaderContext'
107111
- 'GraphqlContext'
108112
- 'JsonContext'
@@ -127,6 +131,7 @@ mongodb-coverage:
127131
contexts:
128132
- 'DoctrineContext':
129133
doctrine: '@doctrine_mongodb'
134+
passwordEncoder: '@security.password_encoder'
130135
- 'HttpHeaderContext'
131136
- 'GraphqlContext'
132137
- 'JsonContext'

features/bootstrap/DoctrineContext.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
use Doctrine\ODM\MongoDB\DocumentManager;
114114
use Doctrine\ORM\EntityManagerInterface;
115115
use Doctrine\ORM\Tools\SchemaTool;
116+
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
116117

117118
/**
118119
* Defines application features from the specific context.
@@ -124,6 +125,7 @@ final class DoctrineContext implements Context
124125
*/
125126
private $manager;
126127
private $doctrine;
128+
private $passwordEncoder;
127129
private $schemaTool;
128130
private $schemaManager;
129131
private $classes;
@@ -135,9 +137,10 @@ final class DoctrineContext implements Context
135137
* You can also pass arbitrary arguments to the
136138
* context constructor through behat.yml.
137139
*/
138-
public function __construct(ManagerRegistry $doctrine)
140+
public function __construct(ManagerRegistry $doctrine, UserPasswordEncoderInterface $passwordEncoder)
139141
{
140142
$this->doctrine = $doctrine;
143+
$this->passwordEncoder = $passwordEncoder;
141144
$this->manager = $doctrine->getManager();
142145
$this->schemaTool = $this->manager instanceof EntityManagerInterface ? new SchemaTool($this->manager) : null;
143146
$this->schemaManager = $this->manager instanceof DocumentManager ? $this->manager->getSchemaManager() : null;
@@ -946,8 +949,7 @@ public function thereAreNodesInAContainer(int $nb, string $uuid)
946949
public function thePasswordForUserShouldBeHashed(string $password, string $user)
947950
{
948951
$user = $this->doctrine->getRepository($this->isOrm() ? User::class : UserDocument::class)->find($user);
949-
950-
if (!password_verify($password, $user->getPassword())) {
952+
if (!$this->passwordEncoder->isPasswordValid($user, $password)) {
951953
throw new \Exception('User password mismatch');
952954
}
953955
}

0 commit comments

Comments
 (0)