Initial Kohana install
[speedfreak] / Server / system / libraries / drivers / Captcha / Math.php
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3  * Captcha driver for "math" style.
4  *
5  * $Id: Math.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_Math_Driver extends Captcha_Driver {
13
14         private $math_exercice;
15
16         /**
17          * Generates a new Captcha challenge.
18          *
19          * @return  string  the challenge answer
20          */
21         public function generate_challenge()
22         {
23                 // Easy
24                 if (Captcha::$config['complexity'] < 4)
25                 {
26                         $numbers[] = mt_rand(1, 5);
27                         $numbers[] = mt_rand(1, 4);
28                 }
29                 // Normal
30                 elseif (Captcha::$config['complexity'] < 7)
31                 {
32                         $numbers[] = mt_rand(10, 20);
33                         $numbers[] = mt_rand(1, 10);
34                 }
35                 // Difficult, well, not really ;)
36                 else
37                 {
38                         $numbers[] = mt_rand(100, 200);
39                         $numbers[] = mt_rand(10, 20);
40                         $numbers[] = mt_rand(1, 10);
41                 }
42
43                 // Store the question for output
44                 $this->math_exercice = implode(' + ', $numbers).' = ';
45
46                 // Return the answer
47                 return array_sum($numbers);
48         }
49
50         /**
51          * Outputs the Captcha riddle.
52          *
53          * @param   boolean  html output
54          * @return  mixed
55          */
56         public function render($html)
57         {
58                 return $this->math_exercice;
59         }
60
61 } // End Captcha Math Driver Class