src/Model/Table/TokensTable.php
public function generateKey($length = null) {
		if (!$length) {
			$length = $this->defaultLength;
		}

		if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
			$function = 'random_bytes';
		} elseif (extension_loaded('openssl')) {
			$function = 'openssl_random_pseudo_bytes';
		} else {
			trigger_error('Not secure', E_USER_DEPRECATED);
			return Random::pwd($length);
		}

		$value = bin2hex($function($length / 2));
		if (strlen($value) !== $length) {
			$value = str_pad($value, $length, '0');
		}
		return $value;
	}
public function generateKey($length = null) {
		if (!$length) {
			$length = $this->defaultLength;
		}

		if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
			$function = 'random_bytes';
		} elseif (extension_loaded('openssl')) {
			$function = 'openssl_random_pseudo_bytes';
		} else {
			trigger_error('Not secure', E_USER_DEPRECATED);
			return Random::pwd($length);
		}

		$value = bin2hex($function($length / 2));
		if (strlen($value) !== $length) {
			$value = str_pad($value, $length, '0');
		}
		return $value;
	}
public function generateKey ( $ length = null ) { if ( ! $ length ) { $ length = $ this -> defaultLength ; } if ( version_compare ( PHP_VERSION , '7.0.0' ) >= 0 ) { $ function = 'random_bytes' ; } elseif ( extension_loaded ( 'openssl' ) ) { $ function = 'openssl_random_pseudo_bytes' ; } else { trigger_error ( 'Not secure' , E_USER_DEPRECATED ) ; return Random :: pwd ( $ length ) ; } $ value = bin2hex ( $ function ( $ length / 2 ) ) ; if ( strlen ( $ value ) !== $ length ) { $ value = str_pad ( $ value , $ length , '0' ) ; } return $ value ; }
Generator of secure random tokens.

Note that it is best to use an even number for the length.

@param int|null $length (defaults to defaultLength)
@return string Key
Generator of secure random tokens .