Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Shared;
   4  
   5  class PasswordHasher
   6  {
   7      /**
   8       * Create a password hash from a given string.
   9       *
  10       * This method is based on the algorithm provided by
  11       * Daniel Rentz of OpenOffice and the PEAR package
  12       * Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
  13       *
  14       * @param string $pPassword Password to hash
  15       *
  16       * @return string Hashed password
  17       */
  18      public static function hashPassword($pPassword)
  19      {
  20          $password = 0x0000;
  21          $charPos = 1; // char position
  22  
  23          // split the plain text password in its component characters
  24          $chars = preg_split('//', $pPassword, -1, PREG_SPLIT_NO_EMPTY);
  25          foreach ($chars as $char) {
  26              $value = ord($char) << $charPos++; // shifted ASCII value
  27              $rotated_bits = $value >> 15; // rotated bits beyond bit 15
  28              $value &= 0x7fff; // first 15 bits
  29              $password ^= ($value | $rotated_bits);
  30          }
  31  
  32          $password ^= strlen($pPassword);
  33          $password ^= 0xCE4B;
  34  
  35          return strtoupper(dechex($password));
  36      }
  37  }