Initial Kohana install
[speedfreak] / Server / system / libraries / drivers / Captcha / Word.php
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3  * Captcha driver for "word" style.
4  *
5  * $Id: Word.php 3769 2008-12-15 00:48:56Z zombor $
6  *
7  * @package    Captcha
8  * @author     Kohana Team
9  * @copyright  (c) 2007-2008 Kohana Team
10  * @license    http://kohanaphp.com/license.html
11  */
12 class Captcha_Word_Driver extends Captcha_Basic_Driver {
13
14         /**
15          * Generates a new Captcha challenge.
16          *
17          * @return  string  the challenge answer
18          */
19         public function generate_challenge()
20         {
21                 // Load words from the current language and randomize them
22                 $words = Kohana::lang('captcha.words');
23                 shuffle($words);
24
25                 // Loop over each word...
26                 foreach ($words as $word)
27                 {
28                         // ...until we find one of the desired length
29                         if (abs(Captcha::$config['complexity'] - strlen($word)) < 2)
30                                 return strtoupper($word);
31                 }
32
33                 // Return any random word as final fallback
34                 return strtoupper($words[array_rand($words)]);
35         }
36
37 } // End Captcha Word Driver Class