\OCP\SecurityISecureRandom

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);

Summary

Methods
Constants
getLowStrengthGenerator()
getMediumStrengthGenerator()
generate()
CHAR_UPPER
CHAR_LOWER
CHAR_DIGITS
CHAR_SYMBOLS
No protected methods found
N/A
No private methods found
N/A

Constants

CHAR_UPPER

CHAR_UPPER

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

CHAR_LOWER

CHAR_LOWER

CHAR_DIGITS

CHAR_DIGITS

CHAR_SYMBOLS

CHAR_SYMBOLS

Methods

getLowStrengthGenerator()

getLowStrengthGenerator() : $this

Convenience method to get a low strength random number generator.

Low Strength should be used anywhere that random strings are needed in a non-cryptographical setting. They are not strong enough to be used as keys or salts. They are however useful for one-time use tokens.

Returns

$this

getMediumStrengthGenerator()

getMediumStrengthGenerator() : $this

Convenience method to get a medium strength random number generator.

Medium Strength should be used for most needs of a cryptographic nature. They are strong enough to be used as keys and salts. However, they do take some time and resources to generate, so they should not be over-used

Returns

$this

generate()

generate(integer  $length, string  $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/') : string

Generate a random string of specified length.

Parameters

integer $length

The length of the generated string

string $characters

An optional list of characters to use if no character list is specified all valid base64 characters are used.

Returns

string