concrete/src/Utility/Service/Identifier.php
public function getString($length = 12)
    {
        $size = ceil($length / 2);

        try {
            if (function_exists('random_bytes')) {
                $bytes = random_bytes($size);
            } else {
                $hash = new PasswordHash(8, false);
                $bytes = $hash->get_random_bytes($size);
            }
        } catch (\Exception $e) {
            die('Could not generate a random string.');
        }

        return substr(bin2hex($bytes), 0, $length);
    }
public function getString($length = 12)
    {
        $size = ceil($length / 2);

        try {
            if (function_exists('random_bytes')) {
                $bytes = random_bytes($size);
            } else {
                $hash = new PasswordHash(8, false);
                $bytes = $hash->get_random_bytes($size);
            }
        } catch (\Exception $e) {
            die('Could not generate a random string.');
        }

        return substr(bin2hex($bytes), 0, $length);
    }
public function getString ( $ length = 12 ) { $ size = ceil ( $ length / 2 ) ; try { if ( function_exists ( 'random_bytes' ) ) { $ bytes = random_bytes ( $ size ) ; } else { $ hash = new PasswordHash ( 8 , false ) ; $ bytes = $ hash -> get_random_bytes ( $ size ) ; } } catch ( \ Exception $ e ) { die ( 'Could not generate a random string.' ) ; } return substr ( bin2hex ( $ bytes ) , 0 , $ length ) ; }
Generate a cryptographically secure random string
@param int $length
@return string
Generate a cryptographically secure random string