@@ -134,7 +134,7 @@ Further in this article, you can find a
134134 .. configuration-block ::
135135
136136 .. code-block :: yaml
137-
137+
138138 # config/packages/test/security.yaml
139139 security :
140140 # ...
@@ -697,6 +697,32 @@ you must register a service for it in order to use it as a named hasher:
697697 This creates a hasher named ``app_hasher `` from a service with the ID
698698``App\Security\Hasher\MyCustomPasswordHasher ``.
699699
700+ Hashing a Stand-Alone String
701+ ----------------------------
702+
703+ The password hasher can be used to hash strings independently
704+ of users. By using the
705+ :class: `Symfony\\ Component\\ PasswordHasher\\ Hasher\\ PasswordHasherFactory `,
706+ you can declare multiple hashers, retrieve any of them with
707+ its name and create hashes. You can then verify that a string matches the given
708+ hash::
709+
710+ use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
711+
712+ // configure different hashers via the factory
713+ $factory = new PasswordHasherFactory([
714+ 'common' => ['algorithm' => 'bcrypt'],
715+ 'sodium' => ['algorithm' => 'sodium'],
716+ ]);
717+
718+ // retrieve the hasher using bcrypt
719+ $hasher = $factory->getPasswordHasher('common');
720+ $hash = $hasher->hash('plain');
721+
722+ // verify that a given string matches the hash calculated above
723+ $hasher->verify($hash, 'invalid'); // false
724+ $hasher->verify($hash, 'plain'); // true
725+
700726.. _passwordhasher-supported-algorithms :
701727
702728Supported Algorithms
0 commit comments