Md5.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\helper\hash;
  12. class Md5
  13. {
  14. protected $salt = 'think';
  15. public function make($value, array $options = [])
  16. {
  17. $salt = isset($options['salt']) ? $options['salt'] : $this->salt;
  18. return md5(md5($value) . $salt);
  19. }
  20. public function check($value, $hashedValue, array $options = [])
  21. {
  22. if (strlen($hashedValue) === 0) {
  23. return false;
  24. }
  25. $salt = isset($options['salt']) ? $options['salt'] : $this->salt;
  26. return md5(md5($value) . $salt) == $hashedValue;
  27. }
  28. public function setSalt($salt)
  29. {
  30. $this->salt = (string)$salt;
  31. return $this;
  32. }
  33. }