diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a93abf4..98e995b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ class Configuration implements ConfigurationInterface ->scalarNode('length')->defaultValue(5)->end() ->scalarNode('width')->defaultValue(120)->end() ->scalarNode('height')->defaultValue(40)->end() + ->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end() ->scalarNode('as_file')->defaultValue(false)->end() ->scalarNode('image_folder')->defaultValue('captcha')->end() ->scalarNode('web_path')->defaultValue('%kernel.root_dir%/../web')->end() diff --git a/README.md b/README.md index 29d9672..f687a20 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ You can define the following type option : * **width**: the width of the captcha image (default=120) * **height**: the height of the captcha image (default=40) * **length**: the length of the captcha (number of chars, default 5) +* **charset**: the charset used for code generation (default=abcdefhjkmnprstuvwxyz23456789) * **as_file**: if set to true an image file will be created instead of embedding to please IE6/7 (default=false) * **image_folder**: name of folder for captcha images relative to public web folder in case **as_file** ist set to true (default="captcha") * **web_path**: absolute path to public web folder (default="%kernel.root_dir%/../web") diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index eb9a8f8..74269bb 100755 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -45,6 +45,12 @@ class CaptchaType extends AbstractType */ protected $asFile; + /** + * Charset used + * @var string + */ + protected $charset; + /** * Folder to save captcha images in, * relative to public web folder @@ -78,7 +84,7 @@ class CaptchaType extends AbstractType /** * Session key - * @var String + * @var string */ private $key = 'captcha'; @@ -91,6 +97,7 @@ class CaptchaType extends AbstractType $this->height = $config['height']; $this->length = $config['length']; $this->asFile = $config['as_file']; + $this->charset = $config['charset']; $this->imageFolder = $config['image_folder']; $this->webPath = $config['web_path']; $this->gcFreq = $config['gc_freq']; @@ -156,8 +163,7 @@ class CaptchaType extends AbstractType { if (!$this->session->has($this->key)) { $value = ''; - $charset = 'abcdefhjkmnprstuvwxyz23456789'; - $chars = str_split($charset); + $chars = str_split($this->charset); for ($i=0; $i<$this->length; $i++) { $value.= $chars[array_rand($chars)];