File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -695,6 +695,32 @@ you must register a service for it in order to use it as a named hasher:
695695 This creates a hasher named ``app_hasher `` from a service with the ID
696696``App\Security\Hasher\MyCustomPasswordHasher ``.
697697
698+ Hashing a Stand-Alone String
699+ ----------------------------
700+
701+ The password hasher can be used to hash strings independently
702+ of users. By using the
703+ :class: `Symfony\\ Component\\ PasswordHasher\\ Hasher\\ PasswordHasherFactory `,
704+ you can declare multiple hashers, retrieve any of them with
705+ its name and create hashes. You can then verify that a string matches the given
706+ hash::
707+
708+ use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
709+
710+ // configure different hashers via the factory
711+ $factory = new PasswordHasherFactory([
712+ 'common' => ['algorithm' => 'bcrypt'],
713+ 'sodium' => ['algorithm' => 'sodium'],
714+ ]);
715+
716+ // retrieve the hasher using bcrypt
717+ $hasher = $factory->getPasswordHasher('common');
718+ $hash = $hasher->hash('plain');
719+
720+ // verify that a given string matches the hash calculated above
721+ $hasher->verify($hash, 'invalid'); // false
722+ $hasher->verify($hash, 'plain'); // true
723+
698724.. _passwordhasher-supported-algorithms :
699725
700726Supported Algorithms
You can’t perform that action at this time.
0 commit comments