In PHP, how do I hash strings in Symfony?

In Symfony, you can hash strings such as passwords using the provided security components. Below is an example of how to hash a string in Symfony using the password encoder service.

// src/Security/PasswordHasher.php namespace App\Security; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; class PasswordHasher { private $passwordHasher; public function __construct(UserPasswordHasherInterface $passwordHasher) { $this->passwordHasher = $passwordHasher; } public function hashPassword($user, $plainPassword) { return $this->passwordHasher->hashPassword( $user, $plainPassword ); } }

keywords: Symfony hash strings password hashing security PHP