Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-15693

gen_rand_string() don't return a string with the expected length

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.2.2
    • Fix Version/s: 3.2.4-RC1
    • Component/s: None
    • Labels:
      None

      Description

      You can check with this script:

      <?php
      function unique_id()
      {
      	return bin2hex(random_bytes(8));
      }
      function gen_rand_string($num_chars = 8)
      {
      	// [a, z] + [0, 9] = 36
      	return substr(strtoupper(base_convert(unique_id(), 16, 36)), 0, $num_chars);
      }
      for($i=0; $i<50; $i++)
          var_dump(gen_rand_string($i)).PHP_EOL;
      
      

      Output:

      string(0) ""
      string(1) "T"
      string(2) "CE"
      string(3) "2VM"
      string(4) "31RL"
      string(5) "NDW2V"
      string(6) "1TRJIT"
      string(7) "2PQDO6F"
      string(8) "1LPIANZF"
      string(9) "1P2DJTWQ1"
      string(10) "C9LEIBH8L6"
      string(11) "14YVKR5UR8U"
      string(12) "37NXW2SRIW8W"
      string(12) "G8IZMLE151QJ"
      string(11) "R3DX4D72URM"
      string(13) "168OHOJFBZH8E"
      string(13) "1S6EIO1OIO3OL"
      string(12) "571VZIW74H2Q"
      string(13) "17XQECQWRCOZ6"
      string(13) "22L1OV0R9VR40"
      string(13) "27BQ6LEIE98GW"
      string(13) "24WC9I1YEGZOC"
      string(12) "X7IRQORO19DZ"
      string(13) "35H0EIEZUQ68G"
      string(13) "209E289KQ7XCO"
      string(12) "AL8N2QSTS3KI"
      string(12) "TLUNEV4PX26M"
      string(13) "3OR6H88SNX4W8"
      string(12) "YUZTORZZ89FX"
      string(13) "25QTZQM9RQV44"
      string(13) "2OTEQ84PGA4GW"
      string(13) "3J4XYMUZ2JACK"
      string(13) "1WO2M7B65S1VR"
      string(13) "3ELWZSUYE2W40"
      string(13) "2D3G2LVIIQF4W"
      string(12) "FKBVW28WXUCL"
      string(12) "E6L7GO26JY3U"
      string(13) "3FKQOEGEV6SK0"
      string(12) "VW12L84722VG"
      string(13) "158GCYLE9QCD6"
      string(12) "YZLYSVWEEUBF"
      string(12) "UOIF5K5F4MHR"
      string(13) "2YI7TZ82UXWKG"
      string(13) "2U63QAAN254W8"
      string(13) "32B8OLL72IWWC"
      string(13) "2K7L1L0E2Y804"
      string(13) "2YW0X4KDU9C04"
      string(13) "2YM148IHP7Y88"
      string(13) "1WZCCIM5EOG2H"
      string(12) "P7CS7KL5UU6R"
      

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Marc Marc
                Reporter:
                rubencm rubencm
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: