Symfony 5.3 - Update password_hashers

This commit is contained in:
Jack Anderson 2023-10-05 13:53:05 +01:00 committed by Clemente Raposo
parent db33001e53
commit fee04d30f9
2 changed files with 15 additions and 9 deletions

View file

@ -2,7 +2,7 @@ security:
enable_authenticator_manager: true
password_hashers:
App\Module\Users\Entity\User:
id: App\Security\LegacyPasswordEncoder
id: App\Security\LegacyPasswordHasher
app_hasher:
id: 'App\Security\LegacyPasswordHasher'

View file

@ -28,35 +28,36 @@
namespace App\Security;
use Symfony\Component\PasswordHasher\Hasher\CheckPasswordLengthTrait;
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
class LegacyPasswordHasher
class LegacyPasswordHasher implements PasswordHasherInterface
{
use CheckPasswordLengthTrait;
/**
* @inheritDoc
*/
public function encodePassword($raw, $salt): string
public function hash($plainPassword): string
{
if ($this->isPasswordTooLong($raw)) {
if ($this->isPasswordTooLong($plainPassword)) {
throw new BadCredentialsException('Invalid password.');
}
return password_hash(strtolower(md5($raw)), PASSWORD_DEFAULT);
return password_hash(strtolower(md5($plainPassword)), PASSWORD_DEFAULT);
}
/**
* @inheritDoc
*/
public function isPasswordValid($encoded, $raw, $salt): bool
public function verify($hashedPassword, $plainPassword): bool
{
if ($this->isPasswordTooLong($raw)) {
if ($this->isPasswordTooLong($plainPassword)) {
return false;
}
$userHash = $encoded;
$password = (md5($raw));
$userHash = $hashedPassword;
$password = (md5($plainPassword));
$valid = self::checkPasswordMD5($password, $userHash);
@ -87,4 +88,9 @@ class LegacyPasswordHasher
return $valid;
}
public function needsRehash(string $hashedPassword): bool
{
return false;
}
}