aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorDavid M <davidmj@users.sourceforge.net>2006-05-19 22:50:25 +0000
committerDavid M <davidmj@users.sourceforge.net>2006-05-19 22:50:25 +0000
commit917eeebc1a3fb19bdbeb479d4e7872c332a57277 (patch)
treeecc5ac8e3bf10b9d80f84b5cefdbc77cdf57a34f /phpBB/includes
parent8e800e333ceae99945cb818709a4aba4de3362b0 (diff)
downloadforums-917eeebc1a3fb19bdbeb479d4e7872c332a57277.tar
forums-917eeebc1a3fb19bdbeb479d4e7872c332a57277.tar.gz
forums-917eeebc1a3fb19bdbeb479d4e7872c332a57277.tar.bz2
forums-917eeebc1a3fb19bdbeb479d4e7872c332a57277.tar.xz
forums-917eeebc1a3fb19bdbeb479d4e7872c332a57277.zip
a few changes ;-)
git-svn-id: file:///svn/phpbb/trunk@5934 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_board.php3
-rw-r--r--phpBB/includes/auth/auth_db.php18
-rw-r--r--phpBB/includes/captcha/captcha_gd.php213
-rw-r--r--phpBB/includes/captcha/fonts/shark.ttfbin46616 -> 0 bytes
-rw-r--r--phpBB/includes/ucp/ucp_register.php12
5 files changed, 227 insertions, 19 deletions
diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php
index 280ef4e395..d54ac32227 100644
--- a/phpBB/includes/acp/acp_board.php
+++ b/phpBB/includes/acp/acp_board.php
@@ -225,6 +225,9 @@ class acp_board
'policy_entropy' => array('lang' => 'CAPTCHA_ENTROPY', 'type' => 'radio:yes_no', 'explain' => false),
'policy_entropy_noise_pixel' => array('lang' => 'ENTROPY_NOISE_PIXEL', 'type' => 'select', 'method' => 'captcha_pixel_noise_select', 'explain' => false),
'policy_entropy_noise_line' => array('lang' => 'ENTROPY_NOISE_LINE', 'type' => 'radio:yes_no', 'explain' => false),
+ 'policy_shape' => array('lang' => 'CAPTCHA_SHAPE', 'type' => 'radio:yes_no', 'explain' => false),
+ 'policy_shape_noise_pixel' => array('lang' => 'SHAPE_NOISE_PIXEL', 'type' => 'select', 'method' => 'captcha_pixel_noise_select', 'explain' => false),
+ 'policy_shape_noise_line' => array('lang' => 'SHAPE_NOISE_LINE', 'type' => 'radio:yes_no', 'explain' => false),
'policy_3dbitmap' => array('lang' => 'CAPTCHA_3DBITMAP', 'type' => 'radio:yes_no', 'explain' => false),
)
);
diff --git a/phpBB/includes/auth/auth_db.php b/phpBB/includes/auth/auth_db.php
index a4a6c8d268..071b61fdfe 100644
--- a/phpBB/includes/auth/auth_db.php
+++ b/phpBB/includes/auth/auth_db.php
@@ -71,15 +71,7 @@ function login_db(&$username, &$password)
if ($confirm_row)
{
- if (strcasecmp($confirm_row['code'], $confirm_code) == 0)
- {
- return array(
- 'status' => LOGIN_ERROR_ATTEMPTS,
- 'error_msg' => 'CONFIRM_CODE_WRONG',
- 'user_row' => $row,
- );
- }
- else
+ if (strcasecmp($confirm_row['code'], $confirm_code) === 0)
{
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
@@ -87,6 +79,14 @@ function login_db(&$username, &$password)
AND confirm_type = " . CONFIRM_LOGIN;
$db->sql_query($sql);
}
+ else
+ {
+ return array(
+ 'status' => LOGIN_ERROR_ATTEMPTS,
+ 'error_msg' => 'CONFIRM_CODE_WRONG',
+ 'user_row' => $row,
+ );
+ }
}
else
{
diff --git a/phpBB/includes/captcha/captcha_gd.php b/phpBB/includes/captcha/captcha_gd.php
index fb7dee7a49..15c082225a 100644
--- a/phpBB/includes/captcha/captcha_gd.php
+++ b/phpBB/includes/captcha/captcha_gd.php
@@ -25,7 +25,7 @@ class captcha
{
global $config;
- $policy_modules = array('policy_entropy', 'policy_occlude', 'policy_3dbitmap');
+ $policy_modules = array('policy_entropy', 'policy_occlude', 'policy_3dbitmap', 'policy_shape');
// Remove all disabled policy modules
foreach ($policy_modules as $key => $name)
@@ -69,6 +69,210 @@ class captcha
}
/**
+ *
+ */
+ function draw_shape($type, $img, $x_min, $y_min, $x_max, $y_max, $color)
+ {
+ switch ($type)
+ {
+ case 'Square':
+ imagefilledpolygon($img, array($x_min, $y_max, $x_min, $y_min, $x_max, $y_min, $x_max, $y_max), 4, $color);
+ break;
+
+ case 'TriangleUp':
+ imagefilledpolygon($img, array($x_min, $y_max, ($x_min + $x_max) / 2, $y_min, $x_max, $y_max), 3, $color);
+ break;
+
+ case 'TriangleDown':
+ imagefilledpolygon($img, array($x_min, $y_min, ($x_min + $x_max) / 2, $y_max, $x_max, $y_min), 3, $color);
+ break;
+
+ case 'Circle':
+ imagefilledellipse($img, ($x_min + $x_max) / 2, ($y_min + $y_max) / 2, $x_max - $x_min, $y_max - $y_min, $color);
+ break;
+ }
+ }
+
+ /**
+ *
+ */
+ function draw_pattern($seed, $img, $x_min, $y_min, $x_max, $y_max, $colors, $thickness = 1)
+ {
+ $x_size = ($x_max - $x_min) / 4;
+ $y_size = ($y_max - $y_min) / 4;
+ $bitmap = substr($seed, 16, 4);
+ $numcolors = sizeof($colors) - 1;
+ for ($y = 0; $y < 4; ++$y)
+ {
+ $map = hexdec(substr($bitmap, $y, 1));
+ for ($x = 0; $x < 4; ++$x)
+ {
+ if ($map & (1 << $x))
+ {
+ $char = hexdec(substr($seed, ($y * 4) + $x, 1));
+ if (!($char >> 2))
+ {
+ switch ($char % 4)
+ {
+ case 0:
+ $shape = 'Circle';
+ break;
+
+ case 1:
+ $shape = 'Square';
+ break;
+
+ case 2:
+ $shape = 'TriangleUp';
+ break;
+
+ case 3:
+ $shape = 'TriangleDown';
+ break;
+ }
+ $this->draw_shape($shape, $img, $x_min + ($x * $x_size), $y_min + ($y * $y_size), $x_min + (($x + 1) * $x_size), $y_min + (($y + 1) * $y_size), $colors[array_rand($colors)]);
+ }
+ }
+ }
+ }
+
+ $cells = array();
+ for ($i = 0; $i < 6; ++$i)
+ {
+ $cells = hexdec(substr($seed, 20 + ($i * 2), 2));
+ $x1 = $cells % 4;
+ $cells = $cells >> 2;
+ $y1 = $cells % 4;
+ $cells = $cells >> 2;
+ $x2 = $cells % 4;
+ $cells = $cells >> 2;
+ $y2 = $cells % 4;
+ $x1_real = $x_min + (($x1 + 0.5) * $x_size);
+ $y1_real = $y_min + (($y1 + 0.5) * $y_size);
+ $x2_real = $x_min + (($x2 + 0.5) * $x_size);
+ $y2_real = $y_min + (($y2 + 0.5) * $y_size);
+ if ($thickness > 1)
+ {
+ imagesetthickness($img,$thickness);
+ }
+ imageline($img, $x1_real, $y1_real, $x2_real, $y2_real, $colors[array_rand($colors)]);
+ if ($thickness > 1)
+ {
+ imagesetthickness($img, 1);
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ function get_char_string()
+ {
+ static $chars = false;
+ static $charcount = 0;
+ if (!$chars)
+ {
+ $chars = array_merge(range('A', 'Z'), range('1', '9'));
+ $charcount = sizeof($chars) - 1;
+ }
+ $word = '';
+ for ($i = mt_rand(6, 8); $i > 0; --$i)
+ {
+ $word .= $chars[mt_rand(0, $charcount)];
+ }
+ return $word;
+ }
+
+ /**
+ * shape
+ */
+ function policy_shape($code)
+ {
+ global $config;
+ // Generate image
+ $img_x = 800;
+ $img_y = 250;
+ $img = imagecreate($img_x, $img_y);
+
+ // Generate colors
+ $background = imagecolorallocate($img, mt_rand(155, 255), mt_rand(155, 255), mt_rand(155, 255));
+ imagefill($img, 0, 0, $background);
+
+ $random = array();
+ $fontcolors = array();
+ for ($i = 0; $i < 15; $i++)
+ {
+ $random[$i] = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
+ $fontcolors[$i] = imagecolorallocate($img, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120));
+ }
+
+ // Generate code characters
+ $characters = array();
+ $sizes = array();
+ $bounding_boxes = array();
+ $width_avail = $img_x;
+ $code_num = sizeof($code);
+
+ // Add some line noise
+ if ($config['policy_shape_noise_line'])
+ {
+ $this->noise_line($img, 0, 0, $img_x, $img_y, $background, $fontcolors, $random);
+ }
+
+ $real = mt_rand(0, 3);
+ $patterns = array('', '', '', '');
+ for ($i = 32; $i > 0; --$i)
+ {
+ $patterns[$i % 4] .= str_pad(dechex(mt_rand(0, 65535)), 4, '0', STR_PAD_LEFT);
+ }
+
+ $char_class = $this->captcha_char('char_ttf');
+ for ($i = 0; $i < 4; ++$i)
+ {
+ if ($i)
+ {
+ $y = 5 + ($i * 60);
+ imageline($img, 550, $y, 650, $y, $fontcolors[0]);
+ }
+ $this->draw_pattern($patterns[$i], $img, 525, 10 + ($i * 60), 575, ($i + 1) * 60, $fontcolors);
+ if ($i == $real)
+ {
+ $this->draw_pattern($patterns[$i], $img, 25, 25, 225, 225, $fontcolors, 3);
+ for ($j = 0; $j < $code_num; ++$j)
+ {
+ $character = new $char_class($code[$j]);
+ $character->drawchar(25, 600 + ($j * 25), 35 + ($i * 60), $img, $background, $fontcolors);
+ }
+ }
+ else
+ {
+ $word = $this->get_char_string();
+ for ($j = strlen($word) - 1; $j >= 0; --$j)
+ {
+ $character = new $char_class(substr($word, $j, 1));
+ $character->drawchar(25, 600 + ($j * 25), 35 + ($i * 60), $img, $background, $fontcolors);
+ }
+ }
+ }
+
+ global $user;
+ imagestring($img, 6, 250, 50, $user->lang['CAPTCHA_LINE_1'], $fontcolors[0]);
+ imagestring($img, 6, 250, 100, $user->lang['CAPTCHA_LINE_2'], $fontcolors[0]);
+ imagestring($img, 6, 250, 150, $user->lang['CAPTCHA_LINE_3'], $fontcolors[0]);
+ imagestring($img, 6, 250, 200, $user->lang['CAPTCHA_LINE_4'], $fontcolors[0]);
+
+
+ // Add some pixel noise
+ if ($config['policy_shape_noise_pixel'])
+ {
+ $this->noise_pixel($img, 0, 0, $img_x, $img_y, $background, $fontcolors, $random, $config['policy_shape_noise_pixel']);
+ }
+
+ // Send image
+ $this->send_image($img);
+ }
+
+ /**
* entropy
*/
function policy_entropy($code)
@@ -126,7 +330,7 @@ class captcha
// Draw the text
$xoffset = 0;
- for ($i = 0, $char_num = sizeof($characters); $i < $char_num; ++$i)
+ for ($i = 0; $i < $code_num; ++$i)
{
$dimm = $bounding_boxes[$i];
$xoffset += ($offset[$i] - $dimm[0]);
@@ -392,8 +596,9 @@ class captcha
// Get the character rendering scheme
$char_class = $this->captcha_char('char_ttf');
+ $code_num = sizeof($code);
- for ($i = 0, $code_num = sizeof($code); $i < $code_num; ++$i)
+ for ($i = 0; $i < $code_num; ++$i)
{
$characters[$i] = new $char_class($code[$i], array('angle' => 0));
$box = $characters[$i]->dimensions($char_size);
@@ -417,7 +622,7 @@ class captcha
$yoffset = mt_rand($med, $max);
- for ($i = 0, $char_num = sizeof($characters); $i < $char_num; ++$i)
+ for ($i = 0; $i < $code_num; ++$i)
{
$dimm = $bounding_boxes[$i];
$offset -= $dimm[0];
diff --git a/phpBB/includes/captcha/fonts/shark.ttf b/phpBB/includes/captcha/fonts/shark.ttf
deleted file mode 100644
index 42b3f78159..0000000000
--- a/phpBB/includes/captcha/fonts/shark.ttf
+++ /dev/null
Binary files differ
diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php
index 2696a2eb1e..c8d37ddf07 100644
--- a/phpBB/includes/ucp/ucp_register.php
+++ b/phpBB/includes/ucp/ucp_register.php
@@ -156,12 +156,7 @@ class ucp_register
if ($row = $db->sql_fetchrow($result))
{
- if (strcasecmp($row['code'], $confirm_code) == 0)
- {
- $error[] = $user->lang['CONFIRM_CODE_WRONG'];
- $wrong_confirm = true;
- }
- else
+ if (strcasecmp($row['code'], $confirm_code) === 0)
{
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
@@ -169,6 +164,11 @@ class ucp_register
AND confirm_type = " . CONFIRM_REG;
$db->sql_query($sql);
}
+ else
+ {
+ $error[] = $user->lang['CONFIRM_CODE_WRONG'];
+ $wrong_confirm = true;
+ }
}
else
{