hash.php 713 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php namespace System;
  2. class Hash {
  3. /**
  4. * The salty, hashed value.
  5. *
  6. * @var string
  7. */
  8. public $value;
  9. /**
  10. * The salt used during hashing.
  11. *
  12. * @var string
  13. */
  14. public $salt;
  15. /**
  16. * Create a new hash instance.
  17. *
  18. * @param string $value
  19. * @param string $salt
  20. * @return void
  21. */
  22. public function __construct($value, $salt = null)
  23. {
  24. $this->salt = (is_null($salt)) ? Str::random(16) : $salt;
  25. $this->value = sha1($value.$this->salt);
  26. }
  27. /**
  28. * Factory for creating hash instances.
  29. *
  30. * @access public
  31. * @param string $value
  32. * @param string $salt
  33. * @return Hash
  34. */
  35. public static function make($value, $salt = null)
  36. {
  37. return new self($value, $salt);
  38. }
  39. }