Development

sfCryptographpPlugin

You must first sign up to be able to contribute.

sfCryptographpPlugin

Use the Cryptographp library to create captchas in Symfony applications.

Installation

  • Install the plugin

    $ symfony plugin-install http://plugins.symfony-project.com/sfCryptographpPlugin

  • Clear your cache
    $ symfony cc

Configure plugin

This plugin can be easily configured with the app.yml file. The example for app.yml below is the default settings in sfCryptographpPlugin/lib/crypt/cryptographp.cfg.php. Include only those settings that you wish to modify.

all:

  cryptographp:
    width:               130
    height:              40
    bg_r:                255               #Background Color RGB
    bg_g:                255
    bg_b:                255
    bg_clear:            true              #transparent background
    bg_img:                                #put an image in the background PNG, GIF or JPG. Enter the image file
    bg_frame:            true              #frame the cryptogram
    char_r:              0                 #font color RGB
    char_g:              0
    char_b:              0
    char_colorrnd:       true
    char_colorrndlevel:  2                  #0 - 4
    char_clear:          10                 #0 = opaque; invisible 127
    fonts:               [luggerbu.ttf]
    letters_range:       ABCDEFGHKLMNPRTWXYZ234569
    letters_easyread:    true               #true alternates consonants and vowels
    letters_rangec:      BCDFGHKLMNPRTVWXZ  #consonants
    letters_rangev:      AEIOUY             #vowels
    difuplow:            false
    char_nb_min:         4                  #minimum number of chars
    char_nb_max:         4                  #maximum number of chars
    char_space:          20                 #space between chars
    char_size_min:       14                 #minimum char size
    char_size_max:       16                 #maximum char size
    char_anglemax:       25                 #maximum angle of rotation of chars (0-360) 
    char_up:             true               #vertical displacement of chars
    effects_gaussianblur:  false            #transform the image blur, Only if PHP> = 5.0.0 
    effects_grayscal:    false              #transform the image to grayscale, Only if PHP> = 5.0.0
    noise_px_min:        10                 #various noise configurations
    noise_px_max:        10
    noise_line_min:      1                  #minimum number of lines to add to the cryptogram
    noise_line_max:      1
    nb_circle_min:       1                  #minimum number of circles to add to the cryptogram
    nb_circle_max:       1
    noise_colorchar:     3
    brushsize:           1
    noiseup:             false
    format:              png
    secure:              md5
    usetimer:            0                  #what do the next 4 settings do??
    usertimererror:      3
    usemax:              1000
    oneuse:              false

See sfCryptographpPlugin/lib/crypt/cryptographp.cfg.php and http://www.captcha.fr/index.php?page=1&langue=en for details about available options.

Use the plugin

Two helper functions can be used in your template

use_helper('Cryptographp');
echo cryptographp_picture();
echo cryptographp_reload();

The first one display the cryptogram as described in the configuration file, the second one is the reload button, if the user can't read the picture and want to use another one.

You must also create a validator for your form with sfCryptographpValidator, like this :

  crypto:
    required:
      msg:        security code required
    sfCryptographpValidator:
      code_error: security code incorrect

Please note that PHP must be compiled with both GD and FreeType to use this plugin. If you do not have FreeType, your captcha image will not appear. Please see this forum thread for an example of the problem: http://www.symfony-project.org/forum/index.php/m/51217/

Versions

1.0.0 => First version, uses Cryptographp 1.3

1.1.0 => Updated to Cryptographp 1.4, and some new options added, thanks to Florian

* The Cryptographp library : http://www.captcha.fr/index.php?page=1&langue=en

Attachments