ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPasswordUtils.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 class ilPasswordUtils
10 {
16  public static function getBytes(int $length) : string
17  {
18  try {
19  return random_bytes($length);
20  } catch (Throwable $ex) {
21  if (!defined('PHP_WINDOWS_VERSION_BUILD') && extension_loaded('openssl')) {
22  $secure = null;
23  $rand = openssl_random_pseudo_bytes($length, $secure);
24  if (false !== $rand && $secure === true) {
25  return $rand;
26  }
27  }
28 
29  $rand = '';
30  for ($i = 0; $i < $length; ++$i) {
31  $rand .= chr(random_int(0, 255));
32  }
33 
34  return $rand;
35  }
36  }
37 }
static getBytes(int $length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
$i
Definition: metadata.php:24