PasswordEncoderInterface.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Core\Encoder;
  11. use Symfony\Component\Security\Core\Exception\BadCredentialsException;
  12. /**
  13. * PasswordEncoderInterface is the interface for all encoders.
  14. *
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. interface PasswordEncoderInterface
  18. {
  19. /**
  20. * Encodes the raw password.
  21. *
  22. * @return string The encoded password
  23. *
  24. * @throws BadCredentialsException If the raw password is invalid, e.g. excessively long
  25. * @throws \InvalidArgumentException If the salt is invalid
  26. */
  27. public function encodePassword(string $raw, ?string $salt);
  28. /**
  29. * Checks a raw password against an encoded password.
  30. *
  31. * @param string $encoded An encoded password
  32. * @param string $raw A raw password
  33. * @param string|null $salt The salt
  34. *
  35. * @return bool true if the password is valid, false otherwise
  36. *
  37. * @throws \InvalidArgumentException If the salt is invalid
  38. */
  39. public function isPasswordValid(string $encoded, string $raw, ?string $salt);
  40. /**
  41. * Checks if an encoded password would benefit from rehashing.
  42. */
  43. public function needsRehash(string $encoded): bool;
  44. }