SimpleSAML_Utilities::generateRandomBytes PHP Method

generateRandomBytes() public static method

Deprecation: This method will be removed in SSP 2.0. Please use openssl_random_pseudo_bytes() instead.
public static generateRandomBytes ( $length )
    public static function generateRandomBytes($length)
    {
        assert('is_int($length)');
        return openssl_random_pseudo_bytes($length);
    }

Usage Example

 /**
  * Construct
  *
  * @param array $authSourceconfig Configuration array for the selected authsource
  * @param array $writeConfig Configuration array for the selected catalogue backend
  * @param array $attributes The user attributes to be saved
  */
 public function __construct($authSourceConfig, $writeConfig, $attributes, $hashAlgo)
 {
     $asc = SimpleSAML_Configuration::loadFromArray($authSourceConfig);
     try {
         $this->dbh = new PDO($asc->getString('dsn'), $asc->getString('username'), $asc->getString('password'));
     } catch (PDOException $e) {
         throw new Exception($e->getMessage());
     }
     $driver = explode(':', $asc->getString('dsn'), 2);
     $driver = strtolower($driver[0]);
     /* Driver specific initialization. */
     switch ($driver) {
         case 'mysql':
             /* Use UTF-8. */
             $this->dbh->exec("SET NAMES utf8");
             $this->dbh->exec("SET CHARACTER SET utf8;");
             break;
         case 'pgsql':
             /* Use UTF-8. */
             $this->dbh->exec("SET NAMES 'UTF8'");
             break;
     }
     $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     $this->attributes = $attributes;
     $this->hashAlgo = $hashAlgo;
     $this->salt = bin2hex(SimpleSAML_Utilities::generateRandomBytes(64, FALSE));
     $wc = SimpleSAML_Configuration::loadFromArray($writeConfig);
     $this->userIdAttr = $wc->getString('user.id.param');
 }
All Usage Examples Of SimpleSAML_Utilities::generateRandomBytes