Welcome Guest, Not a member yet? Register   Sign In
Fixing Captcha helper [php<7]
#1

Hi, i was today trying to use tank_auth with the actual version of CI and i got a big problem, when CI is trying to show a captcha, calling create_captcha from the helper, the server dies for time exceed.

So, reading and reading the code, i find the issue, at line 132 of captcha helper randomize the pool only if random_int exists, working only in php7. For people like me, using 5, must add an else statement.

Let's see, change:
Code:
// PHP7 or a suitable polyfill
if (function_exists('random_int'))
            {
                try
                {
                    for ($i = 0; $i < $word_length; $i++)
                    {
                        $word .= $pool[random_int(0, $rand_max)];
                    }
                }
                catch (Exception $e)
                {
                    // This means fallback to the next possible
                    // alternative to random_int()
                    $word = '';
                }
            }
for:
Code:
// PHP7 or a suitable polyfill
if (function_exists('random_int'))
            {
                try
                {
                    for ($i = 0; $i < $word_length; $i++)
                    {
                        $word .= $pool[random_int(0, $rand_max)];
                    }
                }
                catch (Exception $e)
                {
                    // This means fallback to the next possible
                    // alternative to random_int()
                    $word = '';
                }
            }else{ //PHP5
                for ($i = 0; $i < $word_length; $i++)
                {
                    $word .= $pool[rand(0, strlen($pool) - 1)];
                }
            }

I hope i'm writting the thread at the correct sub-forum. Otherwhise, please tell me or move, i thing this is a big bug.
Reply


Messages In This Thread
Fixing Captcha helper [php<7] - by DiegoMGar - 12-11-2015, 02:27 PM
RE: Fixing Captcha helper [php<7] - by Narf - 12-11-2015, 05:42 PM
RE: Fixing Captcha helper [php<7] - by DiegoMGar - 12-12-2015, 04:09 AM
RE: Fixing Captcha helper [php<7] - by Narf - 12-12-2015, 06:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB