HashManager.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Illuminate\Hashing;
  3. use Illuminate\Support\Manager;
  4. use Illuminate\Contracts\Hashing\Hasher;
  5. class HashManager extends Manager implements Hasher
  6. {
  7. /**
  8. * Create an instance of the Bcrypt hash Driver.
  9. *
  10. * @return \Illuminate\Hashing\BcryptHasher
  11. */
  12. public function createBcryptDriver()
  13. {
  14. return new BcryptHasher($this->app['config']['hashing.bcrypt'] ?? []);
  15. }
  16. /**
  17. * Create an instance of the Argon2 hash Driver.
  18. *
  19. * @return \Illuminate\Hashing\ArgonHasher
  20. */
  21. public function createArgonDriver()
  22. {
  23. return new ArgonHasher($this->app['config']['hashing.argon'] ?? []);
  24. }
  25. /**
  26. * Get information about the given hashed value.
  27. *
  28. * @param string $hashedValue
  29. * @return array
  30. */
  31. public function info($hashedValue)
  32. {
  33. return $this->driver()->info($hashedValue);
  34. }
  35. /**
  36. * Hash the given value.
  37. *
  38. * @param string $value
  39. * @param array $options
  40. * @return string
  41. */
  42. public function make($value, array $options = [])
  43. {
  44. return $this->driver()->make($value, $options);
  45. }
  46. /**
  47. * Check the given plain value against a hash.
  48. *
  49. * @param string $value
  50. * @param string $hashedValue
  51. * @param array $options
  52. * @return bool
  53. */
  54. public function check($value, $hashedValue, array $options = [])
  55. {
  56. return $this->driver()->check($value, $hashedValue, $options);
  57. }
  58. /**
  59. * Check if the given hash has been hashed using the given options.
  60. *
  61. * @param string $hashedValue
  62. * @param array $options
  63. * @return bool
  64. */
  65. public function needsRehash($hashedValue, array $options = [])
  66. {
  67. return $this->driver()->needsRehash($hashedValue, $options);
  68. }
  69. /**
  70. * Get the default driver name.
  71. *
  72. * @return string
  73. */
  74. public function getDefaultDriver()
  75. {
  76. return $this->app['config']['hashing.driver'] ?? 'bcrypt';
  77. }
  78. }