/** * {@inheritdoc} */ public function createSession($userData, $validUntil) { $sessionId = Binary::base64Encode(Random::bytes(32), true); $this->lock['session'] = $sessionId; $this->lock->save(); return $sessionId; }
public function getToken() { if (!isset($this->session['request_token'])) { $this->session['request_token'] = Binary::base64Encode(Random::bytes(32), true); } return $this->session['request_token']; }
/** * Generate a random salt. * @return string Salt. */ public function genSalt() { $bytes = Random::bytes($this->saltLength); $b64 = rtrim(base64_encode($bytes), '='); $salt = Binary::slice(str_replace('+', '.', $b64), 0, $this->saltLength); return $this->prefix . $salt; }
/** * Generate a random sequence of bytes. * @param int $n Number of bytes. * @param string $method Output parameter for the method used to generate * bytes: 'php7', 'mcrypt', 'openssl', 'urandom', or 'mt_rand'. * @return string String of bytes. */ public static function bytes($n, &$method = null) { $bytes = self::php7Bytes($n); $method = 'php7'; if (!isset($bytes)) { $bytes = self::mcryptBytes($n); $method = 'mcrypt'; } if (!isset($bytes)) { $bytes = self::opensslBytes($n); $method = 'openssl'; } if (!isset($bytes)) { $bytes = self::urandomBytes($n); $method = 'urandom'; } if (!isset($bytes)) { $bytes = self::mtRandBytes($n); $method = 'mt_rand'; } $l = Binary::length($bytes); if ($l < $n) { $bytes .= self::mtRandBytes($n - $l); } return $bytes; }