@@ -134,7 +134,7 @@ Further in this article, you can find a
134
134
.. configuration-block ::
135
135
136
136
.. code-block :: yaml
137
-
137
+
138
138
# config/packages/test/security.yaml
139
139
security :
140
140
# ...
@@ -697,6 +697,32 @@ you must register a service for it in order to use it as a named hasher:
697
697
This creates a hasher named ``app_hasher `` from a service with the ID
698
698
``App\Security\Hasher\MyCustomPasswordHasher ``.
699
699
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
+
700
726
.. _passwordhasher-supported-algorithms :
701
727
702
728
Supported Algorithms
0 commit comments