New option for the GD VC. Parameters need some more tweaking

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9283 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Henry Sudhof 2009-01-21 13:37:50 +00:00
parent fce20fd898
commit 7103900847
6 changed files with 55 additions and 6 deletions

View file

@ -41,6 +41,12 @@
<dt><label for="captcha_gd_y_grid">{L_CAPTCHA_GD_Y_GRID}:</label><br /><span>{L_CAPTCHA_GD_Y_GRID_EXPLAIN}</span></dt> <dt><label for="captcha_gd_y_grid">{L_CAPTCHA_GD_Y_GRID}:</label><br /><span>{L_CAPTCHA_GD_Y_GRID_EXPLAIN}</span></dt>
<dd><input id="captcha_gd_y_grid" name="captcha_gd_y_grid" value="{CAPTCHA_GD_Y_GRID}" type="text" /></dd> <dd><input id="captcha_gd_y_grid" name="captcha_gd_y_grid" value="{CAPTCHA_GD_Y_GRID}" type="text" /></dd>
</dl> </dl>
<dl>
<dt><label for="captcha_gd_wave">{L_CAPTCHA_GD_WAVE}:</label><br /><span>{L_CAPTCHA_GD_WAVE_EXPLAIN}</span></dt>
<dd><label><input id="captcha_gd_wave" name="captcha_gd_wave" value="0" class="radio" type="radio"<!-- IF not CAPTCHA_GD_WAVE --> checked="checked"<!-- ENDIF --> /> {L_OFF}</label>
<label><input name="captcha_gd_wave" value="1" class="radio" type="radio"<!-- IF CAPTCHA_GD_WAVE == 1 --> checked="checked"<!-- ENDIF --> /> {L_ON}</label>
</dd>
</dl>
<!-- ENDIF --> <!-- ENDIF -->
</fieldset> </fieldset>

View file

@ -29,12 +29,12 @@ class acp_captcha
$user->add_lang('acp/board'); $user->add_lang('acp/board');
$captcha_vars = array( $captcha_vars = array(
'captcha_gd_x_grid' => 'CAPTCHA_GD_X_GRID', 'captcha_gd_x_grid' => 'CAPTCHA_GD_X_GRID',
'captcha_gd_y_grid' => 'CAPTCHA_GD_Y_GRID', 'captcha_gd_y_grid' => 'CAPTCHA_GD_Y_GRID',
'captcha_gd_foreground_noise' => 'CAPTCHA_GD_FOREGROUND_NOISE', 'captcha_gd_foreground_noise' => 'CAPTCHA_GD_FOREGROUND_NOISE',
'captcha_gd' => 'CAPTCHA_GD_PREVIEWED' 'captcha_gd' => 'CAPTCHA_GD_PREVIEWED',
'captcha_gd_wave' => 'CAPTCHA_GD_WAVE',
); );
if (isset($_GET['demo'])) if (isset($_GET['demo']))

View file

@ -27,6 +27,7 @@ class captcha
var $width = 360; var $width = 360;
var $height = 96; var $height = 96;
/** /**
* Create the image containing $code with a seed of $seed * Create the image containing $code with a seed of $seed
*/ */
@ -34,7 +35,7 @@ class captcha
{ {
global $config; global $config;
srand($seed); srand($seed);
mt_srand($seed); //mt_srand($seed);
// Create image // Create image
$img = imagecreatetruecolor($this->width, $this->height); $img = imagecreatetruecolor($this->width, $this->height);
@ -98,8 +99,8 @@ class captcha
imagedashedline($img, mt_rand($x -3, $x + 3), mt_rand(0, 4), mt_rand($x -3, $x + 3), mt_rand($this->height - 5, $this->height), $current_colour); imagedashedline($img, mt_rand($x -3, $x + 3), mt_rand(0, 4), mt_rand($x -3, $x + 3), mt_rand($this->height - 5, $this->height), $current_colour);
} }
} }
$xoffset = 5; $xoffset = 5;
for ($i = 0; $i < $code_len; ++$i) for ($i = 0; $i < $code_len; ++$i)
{ {
$dimm = $bounding_boxes[$i]; $dimm = $bounding_boxes[$i];
@ -109,12 +110,14 @@ class captcha
$characters[$i]->drawchar($sizes[$i], $xoffset, $yoffset, $img, $colour->get_resource('background'), $scheme); $characters[$i]->drawchar($sizes[$i], $xoffset, $yoffset, $img, $colour->get_resource('background'), $scheme);
$xoffset += $dimm[2]; $xoffset += $dimm[2];
} }
if ($config['captcha_gd_wave'])
{
$this->wave($img);
}
if ($config['captcha_gd_foreground_noise']) if ($config['captcha_gd_foreground_noise'])
{ {
$this->noise_line($img, 0, 0, $this->width, $this->height, $colour->get_resource('background'), $scheme, $bg_colours); $this->noise_line($img, 0, 0, $this->width, $this->height, $colour->get_resource('background'), $scheme, $bg_colours);
} }
// Send image // Send image
header('Content-Type: image/png'); header('Content-Type: image/png');
header('Cache-control: no-cache, no-store'); header('Cache-control: no-cache, no-store');
@ -122,6 +125,38 @@ class captcha
imagedestroy($img); imagedestroy($img);
} }
/**
* Sinus
*/
function wave($img)
{
global $config;
$period_x = mt_rand(8,18);
$period_y = mt_rand(5,14);
$amp_x = mt_rand(5,10);
$amp_y = mt_rand(2,4);
$socket = mt_rand(0,100);
$dampen_x = mt_rand($this->width/5, $this->width/2);
$dampen_y = mt_rand($this->height/5, $this->height/2);
$direction_x = (mt_rand (0, 1));
$direction_y = (mt_rand (0, 1));
for ($i = 0; $i < $this->width; $i++)
{
$dir = ($direction_x) ? $i : ($this->width - $i);
imagecopy($img, $img, $i-1, sin($socket+ $i/($period_x + $dir/$dampen_x)) * $amp_x, $i, 0, 1, $this->height);
}
$socket = mt_rand(0,100);
for ($i = 0; $i < $this->height; $i++)
{
$dir = ($direction_y) ? $i : ($this->height - $i);
imagecopy($img, $img ,sin($socket + $i/($period_y + ($dir)/$dampen_y)) * $amp_y, $i-1, 0, $i, $this->width, 1);
}
return $img;
}
/** /**
* Noise line * Noise line
*/ */

View file

@ -2035,6 +2035,11 @@ function change_database_data(&$no_updates, $version)
// Changes from 3.0.4-RC1 to 3.0.4 // Changes from 3.0.4-RC1 to 3.0.4
case '3.0.4-RC1': case '3.0.4-RC1':
break; break;
// Changes from 3.0.4 to 3.0.4dev
case '3.0.4':
set_config('captcha_gd_wave', 0);
break;
} }
} }

View file

@ -64,6 +64,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_foreground_noise', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_foreground_noise', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_x_grid', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_x_grid', '25');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_y_grid', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_y_grid', '25');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_wave', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_attachment_content', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_attachment_content', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_dnsbl', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_dnsbl', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('chg_passforce', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('chg_passforce', '0');

View file

@ -243,6 +243,8 @@ $lang = array_merge($lang, array(
'CAPTCHA_GD_X_GRID_EXPLAIN' => 'Use lower settings of this to make the GD based CAPTCHA harder. 0 will disable x-axis background noise.', 'CAPTCHA_GD_X_GRID_EXPLAIN' => 'Use lower settings of this to make the GD based CAPTCHA harder. 0 will disable x-axis background noise.',
'CAPTCHA_GD_Y_GRID' => 'GD CAPTCHA background noise y-axis', 'CAPTCHA_GD_Y_GRID' => 'GD CAPTCHA background noise y-axis',
'CAPTCHA_GD_Y_GRID_EXPLAIN' => 'Use lower settings of this to make the GD based CAPTCHA harder. 0 will disable y-axis background noise.', 'CAPTCHA_GD_Y_GRID_EXPLAIN' => 'Use lower settings of this to make the GD based CAPTCHA harder. 0 will disable y-axis background noise.',
'CAPTCHA_GD_WAVE' => 'GD CAPTCHA wave distortion',
'CAPTCHA_GD_WAVE_EXPLAIN' => 'This applies a wave distortion to the captcha.',
'CAPTCHA_PREVIEW_MSG' => 'Your changes to the visual confirmation setting were not saved. This is just a preview.', 'CAPTCHA_PREVIEW_MSG' => 'Your changes to the visual confirmation setting were not saved. This is just a preview.',
'CAPTCHA_PREVIEW_EXPLAIN' => 'The CAPTCHA as it will look like using the current settings. Use the preview button to refresh. Note that captchas are randomized and will differ from one view to the next.', 'CAPTCHA_PREVIEW_EXPLAIN' => 'The CAPTCHA as it will look like using the current settings. Use the preview button to refresh. Note that captchas are randomized and will differ from one view to the next.',