PageRenderTime 68ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/captcha/classes/libraries/captcha/driver/math.php

http://github.com/enormego/EightPHP
PHP | 55 lines | 24 code | 6 blank | 25 comment | 2 complexity | fb7267b3d9e1f917c912f4dab9c22c2e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Captcha driver for "math" style.
  4. *
  5. * @package Modules
  6. * @subpackage Captcha
  7. * @author EightPHP Development Team
  8. * @copyright (c) 2009-2010 EightPHP
  9. * @license http://license.eightphp.com
  10. */
  11. class Captcha_Driver_Math_Core extends Captcha_Driver {
  12. private $math_exercice;
  13. /**
  14. * Generates a new Captcha challenge.
  15. *
  16. * @return string the challenge answer
  17. */
  18. public function generate_challenge() {
  19. // Easy
  20. if(Captcha::$config['complexity'] < 4) {
  21. $numbers[] = mt_rand(1, 5);
  22. $numbers[] = mt_rand(1, 4);
  23. }
  24. // Normal
  25. elseif(Captcha::$config['complexity'] < 7) {
  26. $numbers[] = mt_rand(10, 20);
  27. $numbers[] = mt_rand(1, 10);
  28. }
  29. // Difficult, well, not really ;)
  30. else {
  31. $numbers[] = mt_rand(100, 200);
  32. $numbers[] = mt_rand(10, 20);
  33. $numbers[] = mt_rand(1, 10);
  34. }
  35. // Store the question for output
  36. $this->math_exercice = implode(' + ', $numbers).' = ';
  37. // Return the answer
  38. return array_sum($numbers);
  39. }
  40. /**
  41. * Outputs the Captcha riddle.
  42. *
  43. * @param boolean html output
  44. * @return mixed
  45. */
  46. public function render($html) {
  47. return $this->math_exercice;
  48. }
  49. } // End Captcha Math Driver Class