酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

48 lines
1.5 KiB

  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;
  12. class Hash
  13. {
  14. protected static $handle = [];
  15. public static function make($value, $type = null, array $options = [])
  16. {
  17. return self::handle($type)->make($value, $options);
  18. }
  19. public static function check($value, $hashedValue, $type = null, array $options = [])
  20. {
  21. return self::handle($type)->check($value, $hashedValue, $options);
  22. }
  23. public static function handle($type)
  24. {
  25. if (is_null($type)) {
  26. if (PHP_VERSION_ID >= 50500) {
  27. $type = 'bcrypt';
  28. } else {
  29. $type = 'md5';
  30. }
  31. }
  32. if (empty(self::$handle[$type])) {
  33. $class = "\\think\\helper\\hash\\" . ucfirst($type);
  34. if (!class_exists($class)) {
  35. throw new \ErrorException("Not found {$type} hash type!");
  36. }
  37. self::$handle[$type] = new $class();
  38. }
  39. return self::$handle[$type];
  40. }
  41. }