Copyright (c) 2007 Voznyak Nazar
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
sfCaptcha plugin
The sfCaptchaPlugin is a symfony plugin that provides captcha functionality based on JpGraph library.
It gives you the lib (incl. jpgraph antispam) and the module to secure your symfony forms in a minute with a good captcha.
Installation
Install the plugin
symfony plugin-install http://plugins.symfony-project.com/sfCaptchaPlugin
Enable one or more modules in your settings.yml (optional)
Put JpGraph core and antispam extension into lib folder or modify in
Captcha.class.php the following line:
- require_once 'jpgraph/jpgraph_antispam.php';
Clear you cache
symfony cc
Secure your application
To secure a symfony form:
Optionally add the following routing rules to routing.yml
sf_captcha:
url: /captcha
param: { module: sfCaptcha, action: index }
Put the following lines inside of your form
Put the following code into your form's validator yml file:
methods:
post: [ captcha ]
names:
captcha:
required: Yes
required_msg: You should specify Turing number
validators: captchaValidator
captchaValidator:
class: captchaValidator
param:
error: You should specify valid Turing number
Put the following code into the action which is for the form where captcha
has to be presented:
$g = new Captcha();
$this->getUser()->setAttribute('captcha', $g->generate());
If you want to customize your captcha phrase please modify the following
method in lib/Captcha.class.php:
public function generate() {
$this->iData = '';
for ($i = 0; $i < 5; ++$i)
$this->iData .= chr(ord('1') + rand(0,8));
return $this->iData;
}
You're done. Now, if you try to access a secured form, you will be asked to type in captcha.
TODO