PasswordInterface.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Drupal\Core\Password;
  3. /**
  4. * Secure password hashing functions for user authentication.
  5. */
  6. interface PasswordInterface {
  7. /**
  8. * Maximum password length.
  9. */
  10. const PASSWORD_MAX_LENGTH = 512;
  11. /**
  12. * Hash a password using a secure hash.
  13. *
  14. * @param string $password
  15. * A plain-text password.
  16. *
  17. * @return string
  18. * A string containing the hashed password, or FALSE on failure.
  19. */
  20. public function hash($password);
  21. /**
  22. * Check whether a plain text password matches a hashed password.
  23. *
  24. * @param string $password
  25. * A plain-text password
  26. * @param string $hash
  27. * A hashed password.
  28. *
  29. * @return bool
  30. * TRUE if the password is valid, FALSE if not.
  31. */
  32. public function check($password, $hash);
  33. /**
  34. * Check whether a hashed password needs to be replaced with a new hash.
  35. *
  36. * This is typically called during the login process when the plain text
  37. * password is available. A new hash is needed when the desired iteration
  38. * count has changed by a modification of the password-service in the
  39. * dependency injection container or if the user's password hash was
  40. * generated in an update like user_update_7000() (see the Drupal 7
  41. * documentation).
  42. *
  43. * @param string $hash
  44. * The existing hash to be checked.
  45. *
  46. * @return bool
  47. * TRUE if the hash is outdated and needs rehash.
  48. */
  49. public function needsRehash($hash);
  50. }