[DEV] new_captcha_mod

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
spacetrace
Registered User
Posts: 24
Joined: Tue May 24, 2005 12:43 pm
Location: Kiel
Contact:

[DEV] new_captcha_mod

Post by spacetrace »

MOD Title: new_captcha_mod
MOD Description:
## This Mod replaces the standard captcha visual confirmation image in phpBB
## with a better one, that is not so easily read by text-recognizing mechanisms.
## you can easily replace the fonts, so the dificulty will approve,
## just replace the fonts in the captchafonts folder

Requirement: php with gdlib (standard since php4)

Features:
## different Colors for each character
## characters are not in line
## the hostname is written inside the image, so it is always visible where the captcha comes from
## characters use different fonts
## fonts are easily replaceable

MOD Version: 0.1.0

MOD Download: http://www.spacetrace.com/forum/mods/ne ... ha_mod.zip
Last Stable version: http://www.spacetrace.com/forum/mods/ne ... ha_mod.zip

Demo Board: http://www.spacetrace.com/forum/
cool space online game:
www.spacetrace.org
User avatar
beggers
Registered User
Posts: 1257
Joined: Fri Nov 23, 2001 8:19 pm
Location: Las Vegas
Contact:

Post by beggers »

I'm glad to see that someone has created a more secure version of this feature.
User avatar
vrflyer
Registered User
Posts: 503
Joined: Mon Feb 17, 2003 8:27 pm

Post by vrflyer »

Nice, but could do w/o the "spacetrace" info, unless there is some sort of legal reason for doing this... :P
Always Under Construction !
spacetrace
Registered User
Posts: 24
Joined: Tue May 24, 2005 12:43 pm
Location: Kiel
Contact:

Post by spacetrace »

vrflyer wrote: Nice, but could do w/o the "spacetrace" info, unless there is some sort of legal reason for doing this... :P
what you see is not a spacetrace version!

it is the host that is in $_SERVER[HTTP_HOST] what you see.

if you install it elsewhere, there is another text visible.

this insures, that the image is not stolen by hackers to show it elsewhere to get other people to ready it for them. (a ususal concept for going around the captcha for spam-bots)
cool space online game:
www.spacetrace.org
User avatar
vrflyer
Registered User
Posts: 503
Joined: Mon Feb 17, 2003 8:27 pm

Post by vrflyer »

I understand now... :wink:
Always Under Construction !
smartjean4u
Registered User
Posts: 36
Joined: Wed Apr 19, 2006 2:44 pm
Location: Pondicherry
Contact:

Post by smartjean4u »

well that case sensitive off mod is really superb ! since the confirmation code is case sensitive i lost many members ! Members don't notice the words written as case sensitve because they become confirmation blind !

But that mod was really good ! and also i want to change the case senstive warning in my forum ! i mean the text below the case sensitive can anyone help me please !
Rudy64
Registered User
Posts: 37
Joined: Mon Apr 08, 2002 5:18 am
Location: Canton, MI USA

Post by Rudy64 »

I got this installed quickly, but it's not quite working. I get the background image and the hostname, but the fonts are not showing up. The TTF fonts are uploaded where they need to be, and they were uploaded in binary. I'm planning on uploading some bizarre fonts I have once I get this working. ;)

My PHP was compiled with TTF and GD support, and I do not get the error messages saying this support is not available.

Not sure where to start checking for a problem...any ideas? It's like the only thing not outputting is the character string for the CAPTCHA text.
-= N =-

Definition of oxymoron: good internet provider
spacetrace
Registered User
Posts: 24
Joined: Tue May 24, 2005 12:43 pm
Location: Kiel
Contact:

Post by spacetrace »

maybe you get it working with the standard fonts if you change this line in usercp_confirm.php:

Code: Select all

if (function_exists(imagettftext) && count($fonts) > 0) {
to

Code: Select all

if (1==2 && function_exists(imagettftext) && count($fonts) > 0) {
then it uses the built-in fonts anyway. this will not solve your problem that you cannot use your own fonts, but its a start for searching the bug.
... maybe a phpversion, that doesent work with custom fonts?
our forum runs on
PHP Version 4.3.10-16
see: http://www.spacetrace.com/test.php
cool space online game:
www.spacetrace.org
spacetrace
Registered User
Posts: 24
Joined: Tue May 24, 2005 12:43 pm
Location: Kiel
Contact:

Post by spacetrace »

smartjean4u wrote: well that case sensitive off mod is really superb ! since the confirmation code is case sensitive i lost many members ! Members don't notice the words written as case sensitve because they become confirmation blind !
i guess you are talking about this mod:
http://www.phpbb.com/phpBB/viewtopic.php?t=269750
But that mod was really good ! and also i want to change the case senstive warning in my forum ! i mean the text below the case sensitive can anyone help me please !
search in your forum files for 'Confirm_code_explain'
you have to change it for every language, for english, you find it in
forum\language\lang_english\lang_main.php
cool space online game:
www.spacetrace.org
Rudy64
Registered User
Posts: 37
Joined: Mon Apr 08, 2002 5:18 am
Location: Canton, MI USA

Post by Rudy64 »

spacetrace wrote: maybe you get it working with the standard fonts if you change this line in usercp_confirm.php:

Code: Select all

if (function_exists(imagettftext) && count($fonts) > 0) {
to

Code: Select all

if (1==2 && function_exists(imagettftext) && count($fonts) > 0) {
then it uses the built-in fonts anyway. this will not solve your problem that you cannot use your own fonts, but its a start for searching the bug.


Thanks--I'll try that. Maybe that's a good checkpoint to see if the problem is before or after that point. If I have to, I might throw a few debugging lines in there to show me what's happening.

BTW, I'm running PHP 4.3.10, so we're pretty much on the same page.

EDIT: I changed that line above and your generic font shows up, albeit rather small. So, something in the TTF handling is not working. I am only using the fonts provided with the script right now, and I uploaded it as a subdirectory of the /includes directory.

I'm now wondering if, even though I have TTF support compiled into PHP, I need to do something else (such as insert a config variable in .htaccess) to make it work properly.
-= N =-

Definition of oxymoron: good internet provider
smartjean4u
Registered User
Posts: 36
Joined: Wed Apr 19, 2006 2:44 pm
Location: Pondicherry
Contact:

Post by smartjean4u »

spacetrace wrote

Code: Select all

search in your forum files for 'Confirm_code_explain'
you have to change it for every language, for english, you find it in
forum\language\lang_english\lang_main.php

Thanks SpaceTrace ! Now i could change the text and my users could be aware that the confirmation code is not case sensitive

Thanks !
doneng
Registered User
Posts: 5
Joined: Wed Jul 20, 2005 5:54 am

Post by doneng »

I hade the same exact issue with this and another captcha mod. Making the code changes mentioned below worked, but the text is too small too read. Any suggestions on how to get the fonts bundled with the mod to work?

Here's a link to my php (4.3.10) info page http://macreviewzone.com/info.php


Thanks,

Don
spacetrace wrote: maybe you get it working with the standard fonts if you change this line in usercp_confirm.php:

Code: Select all

if (function_exists(imagettftext) && count($fonts) > 0) {
to

Code: Select all

if (1==2 && function_exists(imagettftext) && count($fonts) > 0) {
User avatar
Kalipo
Registered User
Posts: 551
Joined: Mon Dec 08, 2003 1:47 pm

Post by Kalipo »

This was broke by the 2.0.21 update =/

To make it work (which isn't hard since only one line in the FIND was changed), do the following...

Code: Select all

# 
#-----[ OPEN ]--------------------------------------------- 
# 
includes/usercp_confirm.php

#
#-----[ FIND ]---------------------------------------------
#

$image = create_png($image, $total_width, $total_height);

// Output image
header('Content-Type: image/png');
header('Cache-control: no-cache, no-store');
echo $image;

#
#-----[ REPLACE WITH ]---------------------------------------------
#

	############################ captcha mod start ##################################
	$fonts_path=phpbb_realpath('./' . "includes/captchafonts/");

	$check_captcha=check_captcha_settings();
	#echo $check_captcha[OK];
	if ($check_captcha[error]) echo "<br><br><b>error: ".$check_captcha[error]."</b><br><br>";
	$string = $code;

    // set up image, the first number is the width and the second is the height
    $im = imagecreatetruecolor(220, 80);

    //set colorranges fore- or background
	$cr[0][0]=180;
	$cr[0][1]=250;
	$cr[1][0]=0;
	$cr[1][1]=140;
	$crmode[b]=rand(0,1);
	$crmode[f]=abs($crmode[b]-1);
	
	// creates two variables to store color
    $background = imagecolorallocate($im, rand($cr[$crmode[b]][0], $cr[$crmode[b]][1]), rand($cr[$crmode[b]][0], $cr[$crmode[b]][1]), rand($cr[$crmode[b]][0], $cr[$crmode[b]][1]));
    
    // fill image with bgcolor
    imagefill($im, 0, 0, $background);

    // Get truetype font list
    $fonts = _captcha_font_list($fonts_path);
	
    // writes string
    if (function_exists(imagettftext) && count($fonts) > 0) {

      // write text using a truetype font
      $charSize = 24;        // font size
      $charWidth = 0;        // width of previous character
      $x = 20;               // initial x position
      $y = 40;

      // iterate over characters
      for ($i=0;$i<strlen($string);$i++) {
        // define angle and position of character based on previous character dimension
        $x += ($charWidth * rand(1.0, 1.8));
        $y += rand(-5,5);
        $charAngle = rand(-5,5);
        $charSize += rand(-2,4);
        $char = substr($string,$i,1);

        // select random font
        $font = $fonts[rand(0,count($fonts)-1)];

        // draw character
		$foreground = imagecolorallocate($im, rand($cr[$crmode[f]][0], $cr[$crmode[f]][1]), rand($cr[$crmode[f]][0], $cr[$crmode[f]][1]), rand($cr[$crmode[f]][0], $cr[$crmode[f]][1]));
        imagettftext($im,$charSize,$charAngle,$x,$y,$foreground,$font,$char);

        // capture character dimensions to increment x position
        $bbox = imagettfbbox($charSize,$charAngle,$font,$char);
        $charWidth = max($bbox[0],$bbox[2],$bbox[4],$bbox[6]) - min($bbox[0],$bbox[2],$bbox[4],$bbox[6]);
      }
    }

    else {
      // write text using a built-in font
      $x = 10;
      $y = 0;

      for ($i=0;$i<strlen($string);$i++) {
	  	$foreground = imagecolorallocate($im, rand($cr[$crmode[f]][0], $cr[$crmode[f]][1]), rand($cr[$crmode[f]][0], $cr[$crmode[f]][1]), rand($cr[$crmode[f]][0], $cr[$crmode[f]][1]));
        imagestring($im,5,$x,$y,substr($string,$i,1),$foreground);
        $x += rand(10,15);
        $y += rand(-4,4);
      }

    }

    // strikethrough
    //imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $foreground);
	
    // rotate only if function is defined (many PHP installations have this function missing)
    if (function_exists('imagerotate')) {
      $im2 = imagerotate($im,rand(-20,45),$background);
      imagedestroy($im);
      $im = $im2;
    }
    
    // add cloud only if function is defined (many PHP installations have this function missing)
    if (function_exists('imagecolorallocatealpha')) {
      $middleground = imagecolorallocatealpha($im, rand(160, 200), rand(160, 200), rand(160, 200), 80);

      // random shapes
      for ($x=0; $x<50;$x++) {
        $middleground = imagecolorallocatealpha($im, rand(160, 200), rand(160, 200), rand(160, 200), 80);

		imageline($im, rand(0, 220), rand(0, 220), rand(0, 220), rand(0, 220), $middleground);
        imageellipse($im, rand(0, 220), rand(0, 220), rand(0, 220), rand(0, 220), $middleground);
      }      
	  for ($x=0; $x<15;$x++) {
		$middleground = imagecolorallocatealpha($im, rand(140, 220), rand(140, 220), rand(140, 220), 80);
		imageellipse($im, rand(0, 220), rand(0, 220), rand(0, 220), rand(0, 220), $middleground);
      }
    }
    $hoststring='http://'.$_SERVER['HTTP_HOST'].' only!';
	if (strlen($hoststring)>31) $hoststring=$_SERVER['HTTP_HOST'].' only!';
    if (strlen($hoststring)>31) $hoststring=$_SERVER['HTTP_HOST'];
    imagestring($im,3,2,(imagesy($im)-15),$hoststring,$foreground);
	// Output image
	header('Content-Type: image/png');
	header('Cache-control: no-cache, no-store');
	imagepng($im);
	
	unset($im);
	
	############################ end captcha mod ##################################
alfatek
Registered User
Posts: 32
Joined: Sun Jan 29, 2006 12:04 am
Contact:

Post by alfatek »

Hi,

You really should use a more "modular" approach on how to implement your mod.

Take a look at this one:
http://www.phpbb.com/phpBB/viewtopic.ph ... sc&start=0

everything is kept in a separated file and you just need to change 1 line in the phpbb original code.

More important than that, if all the captcha alternatives are "modular" we can use them randomly! That's gonna be harder for bots :)
Ex0dus
Registered User
Posts: 98
Joined: Mon Nov 01, 2004 1:17 am
Location: Zarasu, Lithuania
Contact:

Post by Ex0dus »

This one really isnt that much worse >_> 2 edits vs 1.

I much prefer this one due to the host name being in the image to trip up bots, though id like it more if it were set as a background instead of on the bottom of the image (since i dont know how well that stops bots).

-Ex0dus
Post Reply

Return to “[2.0.x] MODs in Development”