Nextcloud PHP API (master)

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->get(ISecureRandom::class)->generate(10);

Tags
since
8.0.0

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
since
12.0.0

CHAR_DIGITS

public mixed CHAR_DIGITS = '0123456789'
Tags
since
8.0.0

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
since
23.0.0

CHAR_LOWER

public mixed CHAR_LOWER = 'abcdefghijklmnopqrstuvwxyz'
Tags
since
8.0.0

CHAR_SYMBOLS

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

CHAR_UPPER

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

public mixed CHAR_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Tags
since
8.0.0

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

        
On this page

Search results