public static function getUniqueToken(int $length = 40): string
    {
        $token        = '';
        $codeAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $codeAlphabet .= 'abcdefghijklmnopqrstuvwxyz';
        $codeAlphabet .= '0123456789';
        $max          = strlen($codeAlphabet); // edited

        for ($i = 0; $i < $length; $i++) {
            $token .= $codeAlphabet[self::getSecureRandomInt(0, $max - 1)];
        }

        return $token;
    }
public static function getUniqueToken(int $length = 40): string
    {
        $token        = '';
        $codeAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $codeAlphabet .= 'abcdefghijklmnopqrstuvwxyz';
        $codeAlphabet .= '0123456789';
        $max          = strlen($codeAlphabet); // edited

        for ($i = 0; $i < $length; $i++) {
            $token .= $codeAlphabet[self::getSecureRandomInt(0, $max - 1)];
        }

        return $token;
    }
public static function getUniqueToken ( int $ length = 40 ) : string { $ token = '' ; $ codeAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ; $ codeAlphabet .= 'abcdefghijklmnopqrstuvwxyz' ; $ codeAlphabet .= '0123456789' ; $ max = strlen ( $ codeAlphabet ) ; // edited for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ token .= $ codeAlphabet [ self :: getSecureRandomInt ( 0 , $ max - 1 ) ] ; } return $ token ; }
Generate a unique token

@param int $length

@return string
Generate a unique token