PageRenderTime 106ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 1ms

/classes/captcha/math.php

https://github.com/ascseb/kohana-captcha
PHP | 59 lines | 30 code | 5 blank | 24 comment | 1 complexity | 2a31dba6ba7ee7c658c9b9de97d1c301 MD5 | raw file
  1. <?php defined('SYSPATH') OR die('No direct access.');
  2. /**
  3. * Math captcha class.
  4. *
  5. * @package Captcha
  6. * @author Kohana Team
  7. * @copyright (c) 2008-2009 Kohana Team
  8. * @license http://kohanaphp.com/license.html
  9. */
  10. class Captcha_Math extends Captcha
  11. {
  12. private $math_exercise;
  13. /**
  14. * Generates a new Captcha challenge.
  15. *
  16. * @return string the challenge answer
  17. */
  18. public function generate_challenge()
  19. {
  20. // Easy
  21. if (Captcha::$config['complexity'] < 4)
  22. {
  23. $numbers[] = mt_rand(1, 5);
  24. $numbers[] = mt_rand(1, 4);
  25. }
  26. // Normal
  27. elseif (Captcha::$config['complexity'] < 7)
  28. {
  29. $numbers[] = mt_rand(10, 20);
  30. $numbers[] = mt_rand(1, 10);
  31. }
  32. // Difficult, well, not really ;)
  33. else
  34. {
  35. $numbers[] = mt_rand(100, 200);
  36. $numbers[] = mt_rand(10, 20);
  37. $numbers[] = mt_rand(1, 10);
  38. }
  39. // Store the question for output
  40. $this->math_exercise = implode(' + ', $numbers).' = ';
  41. // Return the answer
  42. return array_sum($numbers);
  43. }
  44. /**
  45. * Outputs the Captcha riddle.
  46. *
  47. * @param boolean html output
  48. * @return mixed
  49. */
  50. public function render($html = TRUE)
  51. {
  52. return $this->math_exercise;
  53. }
  54. } // End Captcha Math Driver Class