ISecureRandom
in
Class SecureRandom provides a wrapper around the random_int function to generate secure random strings. For PHP 7 the native CSPRNG is used, older versions do use a fallback.
Usage: \OC::$server->get(ISecureRandom::class)->generate(10);
Tags
Table of Contents
Constants
- CHAR_ALPHANUMERIC = self::CHAR_UPPER . self::CHAR_LOWER . self::CHAR_DIGITS
- CHAR_DIGITS = '0123456789'
- CHAR_HUMAN_READABLE = 'abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789'
- Characters that can be used for <code>generate($length, $characters)</code>, to generate human-readable random strings. Lower- and upper-case characters and digits are included. Characters which are ambiguous are excluded, such as I, l, and 1 and so on.
- CHAR_LOWER = 'abcdefghijklmnopqrstuvwxyz'
- CHAR_SYMBOLS = '!\"#$%&\\\'()*+,-./:;<=>?@[\]^_`{|}~'
- CHAR_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- Flags for characters that can be used for <code>generate($length, $characters)</code>
Methods
- generate() : string
- Generate a random string of specified length.
Constants
CHAR_ALPHANUMERIC
public
mixed
CHAR_ALPHANUMERIC
= self::CHAR_UPPER . self::CHAR_LOWER . self::CHAR_DIGITS
Tags
CHAR_DIGITS
public
mixed
CHAR_DIGITS
= '0123456789'
Tags
CHAR_HUMAN_READABLE
Characters that can be used for <code>generate($length, $characters)</code>, to generate human-readable random strings. Lower- and upper-case characters and digits are included. Characters which are ambiguous are excluded, such as I, l, and 1 and so on.
public
mixed
CHAR_HUMAN_READABLE
= 'abcdefgijkmnopqrstwxyzABCDEFGHJKLMNPQRSTWXYZ23456789'
Tags
CHAR_LOWER
public
mixed
CHAR_LOWER
= 'abcdefghijklmnopqrstuvwxyz'
Tags
CHAR_SYMBOLS
public
mixed
CHAR_SYMBOLS
= '!\"#$%&\\\'()*+,-./:;<=>?@[\]^_`{|}~'
Tags
CHAR_UPPER
Flags for characters that can be used for <code>generate($length, $characters)</code>
public
mixed
CHAR_UPPER
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Tags
Methods
generate()
Generate a random string of specified length.
public
generate(int $length[, string $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ]) : string
Parameters
- $length : int
-
The length of the generated string
- $characters : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-
An optional list of characters to use if no character list is specified all valid base64 characters are used.