PHP 클래스 Prado\Web\UI\WebControls\TCaptcha

Notice: while this class is easy to use and implement, it does not provide full security. In fact, it's easy to bypass the checks reusing old, already-validated tokens (reply attack). A better alternative is provided by {@link TReCaptcha}. TCaptcha displays a CAPTCHA (a token displayed as an image) that can be used to determine if the input is entered by a real user instead of some program. Unlike other CAPTCHA scripts, TCaptcha does not need session or cookie. The token (a string consisting of alphanumeric characters) displayed is automatically generated and can be configured in several ways. To specify the length of characters in the token, set {@link setMinTokenLength MinTokenLength} and {@link setMaxTokenLength MaxTokenLength}. To use case-insensitive comparison and generate upper-case-only token, set {@link setCaseSensitive CaseSensitive} to false. Advanced users can try to set {@link setTokenAlphabet TokenAlphabet}, which specifies what characters can appear in tokens. The validation of the token is related with two properties: {@link setTestLimit TestLimit} and {@link setTokenExpiry TokenExpiry}. The former specifies how many times a token can be tested with on the server side, and the latter says when a generated token will expire. To specify the appearance of the generated token image, set {@link setTokenImageTheme TokenImageTheme} to be an integer between 0 and 63. And to adjust the generated image size, set {@link setTokenFontSize TokenFontSize} (you may also set {@link TWebControl::setWidth Width}, but the scaled image may not look good.) By setting {@link setChangingTokenBackground ChangingTokenBackground} to true, the image background of the token will be variating even though the token is the same during postbacks. Upon postback, user input can be validated by calling {@link validate()}. The {@link TCaptchaValidator} control can also be used to do validation, which provides client-side validation besides the server-side validation. By default, the token will remain the same during multiple postbacks. A new one can be generated by calling {@link regenerateToken()} manually. The following template shows a typical use of TCaptcha control:
부터: 3.1.1
저자: Qiang Xue ([email protected])
상속: extends TImage
파일 보기 프로젝트 열기: pradosoft/prado

공개 메소드들

메소드 설명
checkRequirements ( ) : boolean Checks the requirements needed for generating CAPTCHA images.
getCaseSensitive ( ) : boolean
getChangingTokenBackground ( ) : boolean
getIsTokenExpired ( ) : boolean
getMaxTokenLength ( ) : integer
getMinTokenLength ( ) : integer
getPrivateKey ( ) : string
getPublicKey ( ) : string
getTestLimit ( ) : integer
getToken ( ) : string
getTokenAlphabet ( ) : string
getTokenExpiry ( ) : integer
getTokenFontSize ( ) : integer
getTokenImageTheme ( ) : integer
onPreRender ( $param ) Configures the image URL that shows the token.
regenerateToken ( ) Regenerates the token to be displayed.
setCaseSensitive ( $value )
setChangingTokenBackground ( $value )
setMaxTokenLength ( $value )
setMinTokenLength ( $value )
setPublicKey ( $value )
setTestLimit ( $value )
setTokenAlphabet ( $value )
setTokenExpiry ( $value )
setTokenFontSize ( $value ) Sets the font size used for displaying the token in an image.
setTokenImageTheme ( $value ) Sets the theme of the token image.
validate ( $input ) : boolean Validates a user input with the token.

보호된 메소드들

메소드 설명
generatePrivateKeyFile ( ) : string Generates a file with a randomly generated private key.
generateRandomKey ( ) : string
generateToken ( $publicKey, $privateKey, $alphabet, $tokenLength, $caseSensitive ) : string Generates the token.
getCaptchaScriptFile ( ) : string
getFontFile ( )
getTokenImageOptions ( ) : string
getTokenLength ( ) : integer
hash2string ( $hex, $alphabet = '' ) : string Converts a hash string into a string with characters consisting of alphanumeric characters.

메소드 상세

checkRequirements() 공개 정적인 메소드

TCaptach requires GD2 with TrueType font support and PNG image support.
public static checkRequirements ( ) : boolean
리턴 boolean whether the requirements are satisfied.

generatePrivateKeyFile() 보호된 메소드

Generates a file with a randomly generated private key.
protected generatePrivateKeyFile ( ) : string
리턴 string the path of the file keeping the private key

generateRandomKey() 보호된 메소드

protected generateRandomKey ( ) : string
리턴 string a randomly generated key

generateToken() 보호된 메소드

Generates the token.
protected generateToken ( $publicKey, $privateKey, $alphabet, $tokenLength, $caseSensitive ) : string
리턴 string the token generated.

getCaptchaScriptFile() 보호된 메소드

protected getCaptchaScriptFile ( ) : string
리턴 string the file path of the PHP script generating the token image

getCaseSensitive() 공개 메소드

public getCaseSensitive ( ) : boolean
리턴 boolean whether the token should be treated as case-sensitive. Defaults to true.

getChangingTokenBackground() 공개 메소드

public getChangingTokenBackground ( ) : boolean
리턴 boolean whether the background of the token image should be variated during postbacks. Defaults to false.

getFontFile() 보호된 메소드

protected getFontFile ( )

getIsTokenExpired() 공개 메소드

public getIsTokenExpired ( ) : boolean
리턴 boolean whether the currently generated token has expired.

getMaxTokenLength() 공개 메소드

public getMaxTokenLength ( ) : integer
리턴 integer the maximum length of the token. Defaults to 6.

getMinTokenLength() 공개 메소드

public getMinTokenLength ( ) : integer
리턴 integer the minimum length of the token. Defaults to 4.

getPrivateKey() 공개 메소드

public getPrivateKey ( ) : string
리턴 string the private key used for generating the token. This is randomly generated and kept in a file for persistency.

getPublicKey() 공개 메소드

public getPublicKey ( ) : string
리턴 string the public key used for generating the token. A random one will be generated and returned if this is not set.

getTestLimit() 공개 메소드

public getTestLimit ( ) : integer
리턴 integer how many times a generated token can be tested. Defaults to 5.

getToken() 공개 메소드

public getToken ( ) : string
리턴 string the token that will be displayed

getTokenAlphabet() 공개 메소드

public getTokenAlphabet ( ) : string
리턴 string the characters that may appear in the token. Defaults to '234578adefhijmnrtABDEFGHJLMNRT'.

getTokenExpiry() 공개 메소드

public getTokenExpiry ( ) : integer
리턴 integer the number of seconds that a generated token will remain valid. Defaults to 600 seconds (10 minutes).

getTokenFontSize() 공개 메소드

public getTokenFontSize ( ) : integer
리턴 integer the font size used for displaying the token in an image. Defaults to 30.

getTokenImageOptions() 보호된 메소드

protected getTokenImageOptions ( ) : string
리턴 string the options to be passed to the token image generator

getTokenImageTheme() 공개 메소드

public getTokenImageTheme ( ) : integer
리턴 integer the theme of the token image. Defaults to 0.

getTokenLength() 보호된 메소드

protected getTokenLength ( ) : integer
리턴 integer the length of the token to be generated.

hash2string() 보호된 메소드

Converts a hash string into a string with characters consisting of alphanumeric characters.
protected hash2string ( $hex, $alphabet = '' ) : string
리턴 string the converted string

onPreRender() 공개 메소드

Configures the image URL that shows the token.
public onPreRender ( $param )

regenerateToken() 공개 메소드

By default, a token, once generated, will remain the same during the following page postbacks. Calling this method will generate a new token.
public regenerateToken ( )

setCaseSensitive() 공개 메소드

public setCaseSensitive ( $value )

setChangingTokenBackground() 공개 메소드

public setChangingTokenBackground ( $value )

setMaxTokenLength() 공개 메소드

public setMaxTokenLength ( $value )

setMinTokenLength() 공개 메소드

public setMinTokenLength ( $value )

setPublicKey() 공개 메소드

public setPublicKey ( $value )

setTestLimit() 공개 메소드

public setTestLimit ( $value )

setTokenAlphabet() 공개 메소드

public setTokenAlphabet ( $value )

setTokenExpiry() 공개 메소드

public setTokenExpiry ( $value )

setTokenFontSize() 공개 메소드

This property affects the generated token image size. The image width is proportional to this font size.
public setTokenFontSize ( $value )

setTokenImageTheme() 공개 메소드

You may test each theme to find out the one you like the most. Below is the explanation of the theme value: It is treated as a 5-bit integer. Each bit toggles a specific feature of the image. Bit 0 (the least significant): whether the image is opaque (1) or transparent (0). Bit 1: whether we should add white noise to the image (1) or not (0). Bit 2: whether we should add a grid to the image (1) or not (0). Bit 3: whether we should add some scribbles to the image (1) or not (0). Bit 4: whether the image background should be morphed (1) or not (0). Bit 5: whether the token text should cast a shadow (1) or not (0).
public setTokenImageTheme ( $value )

validate() 공개 메소드

Validates a user input with the token.
public validate ( $input ) : boolean
리턴 boolean if the user input is not the same as the token.