Function __global->get_secure_random_string

Definitions

sources/crypt.php

  • Generate a cryptographically secure pseudo-random string suitable for tokens, salts, etc.Do not use for passwords; use get_secure_random_password() instead.
  • Visibility: public
  • Is abstract?: No
  • Is static?: No
  • Is final?: No
  • Returns: string

Parameters

Name Type Passed by reference? Variadic? Default Set Range Description
$string_length integer No No 13 N/A N/A The length of the string
$character_map string No No 23456789abcdefghijkmnpqrstuvwxyz N/A N/A A CRYPT_* constant defining the character map to use; the string length should be a power of 2

Returns

  • The pseudo-random string
  • Type: string
  • Set: N/A
  • Range: N/A

Preview

Code (PHP)

/**
 * Generate a cryptographically secure pseudo-random string suitable for tokens, salts, etc.Do not use for passwords; use get_secure_random_password() instead.
 *
 * @param  integer $string_length The length of the string
 * @param  string $character_map A CRYPT_* constant defining the character map to use; the string length should be a power of 2
 * @return string The pseudo-random string
 */

function get_secure_random_string(int $string_length = 13, string $character_map = '23456789abcdefghijkmnpqrstuvwxyz') : string