Nextcloud PHP API (stable18)

ISecureRandom

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->getSecureRandom()->generate(10);

Tags
since
8.0.0

Table of Contents

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>
generate()  : string
Generate a random string of specified length.

Constants

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'

CHAR_LOWER

public mixed CHAR_LOWER = 'abcdefghijklmnopqrstuvwxyz'

CHAR_SYMBOLS

public mixed CHAR_SYMBOLS = '!\"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'

CHAR_UPPER

Flags for characters that can be used for <code>generate($length, $characters)</code>

public mixed CHAR_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

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.

Tags
since
8.0.0
Return values
string

Search results