Symfony UserPasswordEncoderInterface generates different values on each call

I did a simple command in symfony to take a value from the console and encode it:

$io = new SymfonyStyle($input, $output);
$email = $input->getArgument('email');

/** @var User $user */
$user = $this->em->getRepository(User::class)->findOneBy([
    'email' => $email
]);

if (empty($user)) {
    $io->error("User with email '$email' not found");
    return 0;
}

$password = $io->askHidden('Password: ');
$hash = $this->encoder->encodePassword($user, $password);

$io->text("Generated hash: $hash");

Security config fragment:

security:
    encoders:
        AppEntityUser:
            algorithm: bcrypt

    providers:
        app_user_provider:
            entity:
                class: AppEntityUser
                property: email 

Is it okay that each call for the same entered value generates a different value?
How is it possible to verify when accessing that the passwords are the same if for equal values it generates a different encoding?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *