PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/system/libraries/drivers/Captcha/Math.php

http://github.com/ushahidi/Ushahidi_Web
PHP | 61 lines | 29 code | 6 blank | 26 comment | 1 complexity | 930f9a474f7734a3ebb3268bf5d62d44 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2. /**
  3. * Captcha driver for "math" style.
  4. *
  5. * $Id: Math.php 3917 2009-01-21 03:06:22Z 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. private $math_exercice;
  14. /**
  15. * Generates a new Captcha challenge.
  16. *
  17. * @return string the challenge answer
  18. */
  19. public function generate_challenge()
  20. {
  21. // Easy
  22. if (Captcha::$config['complexity'] < 4)
  23. {
  24. $numbers[] = mt_rand(1, 5);
  25. $numbers[] = mt_rand(1, 4);
  26. }
  27. // Normal
  28. elseif (Captcha::$config['complexity'] < 7)
  29. {
  30. $numbers[] = mt_rand(10, 20);
  31. $numbers[] = mt_rand(1, 10);
  32. }
  33. // Difficult, well, not really ;)
  34. else
  35. {
  36. $numbers[] = mt_rand(100, 200);
  37. $numbers[] = mt_rand(10, 20);
  38. $numbers[] = mt_rand(1, 10);
  39. }
  40. // Store the question for output
  41. $this->math_exercice = implode(' + ', $numbers).' = ';
  42. // Return the answer
  43. return array_sum($numbers);
  44. }
  45. /**
  46. * Outputs the Captcha riddle.
  47. *
  48. * @param boolean html output
  49. * @return mixed
  50. */
  51. public function render($html)
  52. {
  53. return $this->math_exercice;
  54. }
  55. } // End Captcha Math Driver Class