diff options
author | Andrey Andreev <narf@bofh.bg> | 2013-04-15 02:32:52 +0200 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2013-04-15 02:32:52 +0200 |
commit | 31da423ebba877984675e7232f100842d58b6dfc (patch) | |
tree | 52532260b5589f3e7d461c75dcd4b8721aece299 | |
parent | 5eb1cbfa673bfa4b8a66ab8a56389a279c1f975b (diff) | |
parent | ffe1bd215fe64dc054296ed8aa1ac253bbf1962b (diff) |
Merge pull request #2396 from abkr/develop
Add options in create_captcha() to specify the randomly generated captcha word length and character pool
-rw-r--r-- | system/helpers/captcha_helper.php | 5 | ||||
-rw-r--r-- | user_guide_src/source/changelog.rst | 1 | ||||
-rw-r--r-- | user_guide_src/source/helpers/captcha_helper.rst | 5 |
3 files changed, 7 insertions, 4 deletions
diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 78e255a15..f3b9c6cc4 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -51,7 +51,7 @@ if ( ! function_exists('create_captcha')) */ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '') { - $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200); + $defaults = array('word' => '', 'img_path' => '', 'img_url' => '', 'img_width' => '150', 'img_height' => '30', 'font_path' => '', 'expiration' => 7200, 'word_length' => 8, 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); foreach ($defaults as $key => $val) { @@ -95,9 +95,8 @@ if ( ! function_exists('create_captcha')) if (empty($word)) { - $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $word = ''; - for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < 8; $i++) + for ($i = 0, $mt_rand_max = strlen($pool) - 1; $i < $word_length; $i++) { $word .= $pool[mt_rand(0, $mt_rand_max)]; } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 65e210761..742dacbae 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -105,6 +105,7 @@ Release Date: Not Released - :doc:`Directory Helper <helpers/directory_helper>` :php:func:`directory_map()` will now append ``DIRECTORY_SEPARATOR`` to directory names in the returned array. - :doc:`Language Helper <helpers/language_helper>` :php:func:`lang()` now accepts an optional list of additional HTML attributes. - Deprecated the :doc:`Email Helper <helpers/email_helper>` as its ``valid_email()``, ``send_email()`` functions are now only aliases for PHP native functions ``filter_var()`` and ``mail()`` respectively. + - :doc:`CAPTCHA Helper <helpers/captcha_helper>` :php:func:`create_captcha` added word_length and pool options for setting length of randomly generated captcha word, and what characters to select from. - Database diff --git a/user_guide_src/source/helpers/captcha_helper.rst b/user_guide_src/source/helpers/captcha_helper.rst index 17462a8de..ca24e011f 100644 --- a/user_guide_src/source/helpers/captcha_helper.rst +++ b/user_guide_src/source/helpers/captcha_helper.rst @@ -62,7 +62,9 @@ Once loaded you can generate a captcha like this:: 'font_path' => './path/to/fonts/texb.ttf', 'img_width' => '150', 'img_height' => 30, - 'expiration' => 7200 + 'expiration' => 7200, + 'word_length' => 8, + 'pool' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ); $cap = create_captcha($vals); @@ -79,6 +81,7 @@ Once loaded you can generate a captcha like this:: - The **expiration** (in seconds) signifies how long an image will remain in the captcha folder before it will be deleted. The default is two hours. +- **word_length** defaults to 8, **pool** defaults to '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' Adding a Database ----------------- |