CCaptchaAction.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec\helpers;
  10. use Yii;
  11. use yii\captcha\CaptchaAction;
  12. /**
  13. * @author Terry Zhao <2358269014@qq.com>
  14. * @since 1.0
  15. */
  16. class CCaptchaAction extends CaptchaAction
  17. {
  18. public $minLength = 4;
  19. public $maxLength = 4;
  20. /**
  21. * Generates a new verification code.
  22. * @return string the generated verification code
  23. */
  24. protected function generateVerifyCode()
  25. {
  26. if ($this->minLength > $this->maxLength) {
  27. $this->maxLength = $this->minLength;
  28. }
  29. if ($this->minLength < 3) {
  30. $this->minLength = 3;
  31. }
  32. if ($this->maxLength > 20) {
  33. $this->maxLength = 20;
  34. }
  35. $length = mt_rand($this->minLength, $this->maxLength);
  36. $letters = [0,1,2,3,4,5,6,7,8,9];
  37. return array_rand($letters).array_rand($letters).array_rand($letters).array_rand($letters);
  38. //$vowels = '01234';
  39. //$code = '';
  40. // for ($i = 0; $i < $length; ++$i) {
  41. //if ($i % 2 && mt_rand(0, 10) > 2 || !($i % 2) && mt_rand(0, 10) > 9) {
  42. // $code .= $vowels[mt_rand(0, 4)];
  43. //} else {
  44. // $code .= $letters[mt_rand(0, 20)];
  45. // }
  46. // }
  47. //return $code;
  48. }
  49. }