PasswordHasher.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /**
  8. * PHPExcel_Shared_PasswordHasher
  9. *
  10. * @category PHPExcel
  11. * @package PHPExcel_Shared
  12. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  13. */
  14. class PHPExcel_Shared_PasswordHasher
  15. {
  16. /**
  17. * Create a password hash from a given string.
  18. *
  19. * This method is based on the algorithm provided by
  20. * Daniel Rentz of OpenOffice and the PEAR package
  21. * Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
  22. *
  23. * @param string $pPassword Password to hash
  24. * @return string Hashed password
  25. */
  26. public static function hashPassword($pPassword = '')
  27. {
  28. $password = 0x0000;
  29. $charPos = 1; // char position
  30. // split the plain text password in its component characters
  31. $chars = preg_split('//', $pPassword, -1, PREG_SPLIT_NO_EMPTY);
  32. foreach ($chars as $char) {
  33. $value = ord($char) << $charPos++; // shifted ASCII value
  34. $rotated_bits = $value >> 15; // rotated bits beyond bit 15
  35. $value &= 0x7fff; // first 15 bits
  36. $password ^= ($value | $rotated_bits);
  37. }
  38. $password ^= strlen($pPassword);
  39. $password ^= 0xCE4B;
  40. return(strtoupper(dechex($password)));
  41. }
  42. }