yii\captcha\CaptchaAction::generateVerifyCode PHP Method

generateVerifyCode() protected method

Generates a new verification code.
protected generateVerifyCode ( ) : string
return string the generated verification code
    protected function generateVerifyCode()
    {
        if ($this->minLength > $this->maxLength) {
            $this->maxLength = $this->minLength;
        }
        if ($this->minLength < 3) {
            $this->minLength = 3;
        }
        if ($this->maxLength > 20) {
            $this->maxLength = 20;
        }
        $length = mt_rand($this->minLength, $this->maxLength);
        $letters = 'bcdfghjklmnpqrstvwxyz';
        $vowels = 'aeiou';
        $code = '';
        for ($i = 0; $i < $length; ++$i) {
            if ($i % 2 && mt_rand(0, 10) > 2 || !($i % 2) && mt_rand(0, 10) > 9) {
                $code .= $vowels[mt_rand(0, 4)];
            } else {
                $code .= $letters[mt_rand(0, 20)];
            }
        }
        return $code;
    }

Usage Example

 protected function generateVerifyCode()
 {
     if ($this->isDigital) {
         if ($this->minLength > $this->maxLength) {
             $this->maxLength = $this->minLength;
         }
         if ($this->minLength < 3) {
             $this->minLength = 3;
         }
         if ($this->maxLength > 20) {
             $this->maxLength = 20;
         }
         $length = mt_rand($this->minLength, $this->maxLength);
         $code = '';
         for ($i = 0; $i < $length; $i++) {
             $code .= mt_rand(0, 9);
         }
         return $code;
     }
     return parent::generateVerifyCode();
 }
All Usage Examples Of yii\captcha\CaptchaAction::generateVerifyCode