CaptchaExtendedAction
extends CCaptchaAction
in package
Yii extended captcha supporting more complex formulas and masking techniques.
Features:
- supported modes: logical, words, mathverbal, math, default
- supported extended characters latin1, latin2 (utf-8) including middle- east- european and cyrillyc characters
- implements masking elements: dots density, through lines, fillSections, font color varying
Installation:
1) unzip CaptchaExtended.zip files into ../protected/extensions/captchaExtended/*.*
2) Register class paths to [CaptchaExtendedAction] and [CaptchaExtendedValidator], e.g. in components/controller.php:
public function init(){
// import class paths for captcha extended
Yii::$classMap = array_merge( Yii::$classMap, array(
'CaptchaExtendedAction' => Yii::getPathOfAlias('ext.captchaExtended').DIRECTORY_SEPARATOR.'CaptchaExtendedAction.php',
'CaptchaExtendedValidator' => Yii::getPathOfAlias('ext.captchaExtended').DIRECTORY_SEPARATOR.'CaptchaExtendedValidator.php'
));
}
3) Define action in controller, e.g. SiteController:
public function actions(){
return array(
'captcha'=>array(
'class'=>'CaptchaExtendedAction',
),
);
}
4) Define client validation in model::rules():
public function rules(){
return array(
array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
}
5) If needed, collect localized strings via CLI command "yiic message messages/config.php" and translate captcha related strings.
6) If needed, you can tune captcha modes and visibility options:
- In "words" mode, you can place your own file [words.txt] or [words.yourlanguage.txt]
- If needed, set the dots density [0-100], the number of through lines [0-] or fillSections [0-], font and background colors
7) Test & enjoy!
Table of Contents
Constants
- MODE_DEFAULT = 'default'
- MODE_LOGICAL = 'logical'
- MODE_MATH = 'math'
- MODE_MATHVERBAL = 'mathverbal'
- MODE_WORDS = 'words'
Properties
- $density : mixed
- Dots density around characters 0 - 100%
- $fileWords : mixed
- Path to the file to be used for generating random words in "words" mode
- $fillSections : mixed
- The number of sections to be filled with random flood color
- $lines : mixed
- The number of lines drawn through the generated captcha picture
- $mode : mixed
- Captcha mode, supported values are [logical, words, mathverbal, math, default].
- $offset : int
- $regenerateOnValid : mixed
- If True, regenerate captcha if user enters valid code
Methods
- getVerifyCode() : string
- Gets the verification code.
- getVerifyResult() : mixed
- Return verification result expected by user
- run() : mixed
- Run action
- validate() : whether
- Validates the input to see if it matches the generated code.
- generateValidationHashCI() : mixed
- Return hash for case insensitive result (converted to lowercase)
- generateVerifyCode() : string
- Generates a new verification code.
- getCodeLogical() : mixed
- Return code for logical formula like min(one,7,four)
- getCodeMath() : mixed
- Return code for math mode like 9+1= or 95-5=
- getCodeMathVerbal() : mixed
- Return code for verbal math mode like "How much is 1 plus 1 ?"
- getCodeWords() : mixed
- Return code for random words from text file.
- getNumber() : mixed
- Return verbal representation for supplied number, like 1 => one
- getNumbers() : mixed
- Return numbers 0..9 translated into word
- purifyWord() : mixed
- Return captcha word without dirty characters like *,/,{,},.. Retain diacritics if unicode supported.
- renderImage() : string
- Renders the CAPTCHA image based on the code.
Constants
MODE_DEFAULT
public
mixed
MODE_DEFAULT
= 'default'
MODE_LOGICAL
public
mixed
MODE_LOGICAL
= 'logical'
MODE_MATH
public
mixed
MODE_MATH
= 'math'
MODE_MATHVERBAL
public
mixed
MODE_MATHVERBAL
= 'mathverbal'
MODE_WORDS
public
mixed
MODE_WORDS
= 'words'
Properties
$density
Dots density around characters 0 - 100%
public
mixed
$density
= 3
$fileWords
Path to the file to be used for generating random words in "words" mode
public
mixed
$fileWords
$fillSections
The number of sections to be filled with random flood color
public
mixed
$fillSections
= 5
$lines
The number of lines drawn through the generated captcha picture
public
mixed
$lines
= 2
$mode
Captcha mode, supported values are [logical, words, mathverbal, math, default].
public
mixed
$mode
= self::MODE_DEFAULT
Default value is [default], which uses native frameworks implementation. Captcha mode examples:
- logical e.g. min(5, one, 9) or max (two, three, 3)
- words e.g. [localized random words] (supports translated strings in UTF-8 including latin2 and cyrillic)
- mathverbal e.g. How much is 12 plus 8 ?
- math e.g. 93 - 3 =
- default e.g. random latin1 characters
$offset
public
int
$offset
= 2
padding around the text. Defaults to 2.
$regenerateOnValid
If True, regenerate captcha if user enters valid code
public
mixed
$regenerateOnValid
= \true
Methods
getVerifyCode()
Gets the verification code.
public
getVerifyCode([bool $regenerate = false ]) : string
Parameters
- $regenerate : bool = false
-
whether the verification code should be regenerated.
Return values
string —the verification code.
getVerifyResult()
Return verification result expected by user
public
getVerifyResult([bool $regenerate = false ]) : mixed
Parameters
- $regenerate : bool = false
run()
Run action
public
run() : mixed
validate()
Validates the input to see if it matches the generated code.
public
validate(string $input, bool $caseSensitive) : whether
Parameters
- $input : string
-
user input
- $caseSensitive : bool
-
whether the comparison should be case-sensitive
Return values
whether —the input is valid
generateValidationHashCI()
Return hash for case insensitive result (converted to lowercase)
protected
generateValidationHashCI(string $result) : mixed
Parameters
- $result : string
generateVerifyCode()
Generates a new verification code.
protected
generateVerifyCode() : string
Return values
string —the generated verification code
getCodeLogical()
Return code for logical formula like min(one,7,four)
protected
getCodeLogical() : mixed
getCodeMath()
Return code for math mode like 9+1= or 95-5=
protected
getCodeMath() : mixed
getCodeMathVerbal()
Return code for verbal math mode like "How much is 1 plus 1 ?"
protected
getCodeMathVerbal() : mixed
getCodeWords()
Return code for random words from text file.
protected
getCodeWords() : mixed
First we'll try to load file for current language, like [words.de.txt] If not found, we will try to load generic file like [words.txt]
getNumber()
Return verbal representation for supplied number, like 1 => one
protected
static getNumber(int $n) : mixed
Parameters
- $n : int
-
The number to be translated
getNumbers()
Return numbers 0..9 translated into word
protected
static getNumbers() : mixed
purifyWord()
Return captcha word without dirty characters like *,/,{,},.. Retain diacritics if unicode supported.
protected
purifyWord(string $w) : mixed
Parameters
- $w : string
-
The word to be purified
renderImage()
Renders the CAPTCHA image based on the code.
protected
renderImage(string $code) : string
Parameters
- $code : string
-
the verification code
Return values
string —image content