Not able to validate the correct username and password in symfony

35 Views Asked by At

I have used following lines of code to create a user.

$newUser = new User();
$plainPassword = 'test';
$hashPassword = $this->passwordEncoder->encodePassword($newUser, $plainPassword);

$newUser->setUserName($filterArray['username']);
$newUser->setPassword($hashPassword);
$newUser->setCreatedDatetime();
$newUser->setStatus('active');

$this->entityManager->persist($newUser);
$this->entityManager->flush();

Now when I try to login

$this->passwordEncoder->isPasswordValid($user, $credentials->getPassword())

This line is always returning false. Here $user outputs

App\Entity\User {#592
  -id: 1
  -loginName: "test"
  -loginPassword: "$2y$13$S5nEPTFznoemyO1.WsBxl.beyGL4i1YuwteDx7GDtzP"
  -createdDatetime: DateTime @1602489653 {#596
    date: 2020-10-12 10:00:53.0 Europe/Berlin (+02:00)
  }
  -status: "active"
}

Can anybody help me on this.

0

There are 0 best solutions below