Captcha clockwise / counter-clockwise

In diesem Forum können Mod-Autoren ihre Mods vorstellen, die sich noch im Entwicklungsstatus befinden. Der Einbau in Foren im produktiven Betrieb wird nicht empfohlen.
Forumsregeln
phpBB 2.0 hat das Ende seiner Lebenszeit überschritten
phpBB 2.0 wird nicht mehr aktiv unterstützt. Insbesondere werden - auch bei Sicherheitslücken - keine Patches mehr bereitgestellt. Der Einsatz von phpBB 2.0 erfolgt daher auf eigene Gefahr. Wir empfehlen einen Umstieg auf phpBB 3.0, welches aktiv weiterentwickelt wird und für welches regelmäßig Updates zur Verfügung gestellt werden.
Antworten
Tuclipse
Mitglied
Beiträge: 1
Registriert: 21.08.2007 17:31

Captcha clockwise / counter-clockwise

Beitrag von Tuclipse »

Hello,

Auf englisch ... :lol:

Use this code below to replace phpbb's default (weak) captcha.
This one is based on a tutorial from php-kurse.com.

Install
====
1. Create a folder named captcha/ in phpBB's main folder.
2. place some .ttf files (Fonts) there, can copy from Windows\fonts
3. Place 2 png's of 250px x 250px named
3a. captcha-counterclock.png
3b. captcha-clock.png
inside the folder

4. copy this code and replace includes/usercp_confirm.php

Code: Alles auswählen

<?php
/***************************************************************************
 *                            usercp_confirm.php
 *                            -------------------
 *   begin                : Saturday, Jan 15, 2003
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   $Id: usercp_confirm.php,v 1.1.2.4 2006/05/30 19:29:43 grahamje Exp $
 *   Modified by Ueli Kistler 2007, captcha clock
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

if ( !defined('IN_PHPBB') )
{
	die('Hacking attempt');
	exit;
}

// Note to potential users of this code ...
//
// Remember this is released under the _GPL_ and is subject
// to that licence. Do not incorporate this within software 
// released or distributed in any way under a licence other
// than the GPL. We will be watching ... ;)

// Do we have an id? No, then just exit
if (empty($HTTP_GET_VARS['id']))
{
	exit;
}

$file[0] = "captcha/captcha-clock.png";
$file[1] = "captcha/captcha-counterclock.png";

$confirm_id = htmlspecialchars($HTTP_GET_VARS['id']);

// Define available charset
$chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',  'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',  'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9');

if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
{
	$confirm_id = '';
}

// Try and grab code for this id and session
$sql = 'SELECT code  
	FROM ' . CONFIRM_TABLE . " 
	WHERE session_id = '" . $userdata['session_id'] . "' 
		AND confirm_id = '$confirm_id'";
$result = $db->sql_query($sql);

// If we have a row then grab data else create a new id
if ($row = $db->sql_fetchrow($result))
{
	$db->sql_freeresult($result);
	$code = $row['code'];
}
else
{
	exit;
}

/**
 Init 
 **/
$phpbb_root_path = str_replace('index.'.$phpEx, '', realpath($phpbb_root_path.'index.'.$phpEx));

$fonts = array();
if ($fonts_dir = opendir($phpbb_root_path.'captcha/'))
{
	while (true == ($fontfile = @readdir($fonts_dir))) 
	{ 
		if ((substr(strtolower($fontfile), -3) == 'ttf'))
		{         
			$fonts[] = $fontfile; 
		}     
	}
	closedir($fonts_dir);
}

// Randomizer
list($usec, $sec) = explode(' ', microtime()); 
mt_srand($sec * $usec); 

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

$codeorg = $code;

// randomize clock/counterclock
if (getDirection() == 0)
{
	$image = ImageCreateFromPNG ($file[0]);
}
else {
	$image = ImageCreateFromPNG ($file[1]);
	$code = strrev($code);
}

ImageTTFText ($image, getSize(), getRotation(), 140,  70, getColour($image), $phpbb_root_path.getFont($fonts), $code[0]);
ImageTTFText ($image, getSize(), getRotation(), 180, 130, getColour($image), $phpbb_root_path.getFont($fonts), $code[1]);
ImageTTFText ($image, getSize(), getRotation(), 130, 210, getColour($image), $phpbb_root_path.getFont($fonts), $code[2]);
ImageTTFText ($image, getSize(), getRotation(),  80, 190, getColour($image), $phpbb_root_path.getFont($fonts), $code[3]);
ImageTTFText ($image, getSize(), getRotation(),  80, 120, getColour($image), $phpbb_root_path.getFont($fonts), $code[4]);
ImageTTFText ($image, getSize(), getRotation(),  90, 50, getColour($image), $phpbb_root_path.getFont($fonts), $code[5]);
ImageTTFText ($image, 12, 0, 0,  240, getColour($image), $phpbb_root_path.getFont($fonts), $codeorg);

// Ausgabe im Format PNG
ImagePng     ($image);

// Resourcen wieder freigeben
ImageDestroy ($image);

unset($image);
exit;

function getDirection()
{
	return mt_rand(0,1);
}

function getColour($image)
{
	return ImageColorAllocate ($image, mt_rand(0, 255),mt_rand(0, 255),mt_rand(0, 255));
}

function getRotation()
{
	return mt_rand(-90,90);
}

function getSize()
{
	return mt_rand(20,32);
}

function getFont($fonts)
{
	return '/captcha/'.$fonts[rand(0, (count($fonts)-1))];
}

?>
Axl
Mitglied
Beiträge: 1
Registriert: 24.08.2007 05:51

Captcha-Clock

Beitrag von Axl »

Hi,

Thanks Tuclipse for take over to phpBB.
In english too (not my Native language)

You can use the picture for the captcha-clock from:
www.php-kurs.com/captcha-erstellen.htm
Its open source (i have done it :) )

Some Suggestions:
Define available charset - NO use of 6 or 9, 0,o or O, P or d, I or 1 because of confounding danger - rotate a 9 and you get 6 :grin:
The Rotation is nice, but to heavy for the design.

Code: Alles auswählen

<?php
/***************************************************************************
 *                            usercp_confirm.php
 *                            -------------------
 *   begin                : Saturday, Jan 15, 2003
 *   copyright            : (C) 2001 The phpBB Group
 *   email                : support@phpbb.com
 *
 *   based on             : Captcha-Clock from
 *                          www.php-kurs.com/captcha-erstellen.htm
 *                          (you can get there the picture and impression)
 *
 *   $Id: usercp_confirm.php,v 1.1.2.4 2006/05/30 19:29:43 grahamje Exp $
 *   Modified by Ueli Kistler 2007, captcha clock
 *   Modified by Axel Pratzner 2007, captcha clock
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

if ( !defined('IN_PHPBB') )
{
   die('Hacking attempt');
   exit;
}

// Note to potential users of this code ...
//
// Remember this is released under the _GPL_ and is subject
// to that licence. Do not incorporate this within software
// released or distributed in any way under a licence other
// than the GPL. We will be watching ... ;)

// Do we have an id? No, then just exit
if (empty($HTTP_GET_VARS['id']))
{
   exit;
}

$file[0] = "captcha/captcha-clock.png";
$file[1] = "captcha/captcha-counterclock.png";

$confirm_id = htmlspecialchars($HTTP_GET_VARS['id']);

// Define available charset
// NO use of 6 or 9, 0,o or O, P or d, and I or 1 
// because of confounding danger
$chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',  'K', 'L', 'M', 'N', 'Q', 'R', 'S', 'T',  'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '7', '8');

if (!preg_match('/^[A-Za-z0-9]+$/', $confirm_id))
{
   $confirm_id = '';
}

// Try and grab code for this id and session
$sql = 'SELECT code
   FROM ' . CONFIRM_TABLE . "
   WHERE session_id = '" . $userdata['session_id'] . "'
      AND confirm_id = '$confirm_id'";
$result = $db->sql_query($sql);

// If we have a row then grab data else create a new id
if ($row = $db->sql_fetchrow($result))
{
   $db->sql_freeresult($result);
   $code = $row['code'];
}
else
{
   exit;
}

/**
 Init
 **/
$phpbb_root_path = str_replace('index.'.$phpEx, '', realpath($phpbb_root_path.'index.'.$phpEx));

$fonts = array();
if ($fonts_dir = opendir($phpbb_root_path.'captcha/'))
{
   while (true == ($fontfile = @readdir($fonts_dir)))
   {
      if ((substr(strtolower($fontfile), -3) == 'ttf'))
      {
         $fonts[] = $fontfile;
      }
   }
   closedir($fonts_dir);
}

// Randomizer
list($usec, $sec) = explode(' ', microtime());
mt_srand($sec * $usec);

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

$codeorg = $code;

// randomize clock/counterclock
if (getDirection() == 0)
{
   $image = ImageCreateFromPNG ($file[0]);
}
else {
   $image = ImageCreateFromPNG ($file[1]);
   $code = strrev($code);
}

ImageTTFText ($image, getSize(), -30, 140,  70, getColour($image), $phpbb_root_path.getFont($fonts), $code[0]);
ImageTTFText ($image, getSize(), -90, 180, 110, getColour($image), $phpbb_root_path.getFont($fonts), $code[1]);
ImageTTFText ($image, getSize(), -110, 175, 155, getColour($image), $phpbb_root_path.getFont($fonts), $code[2]);
ImageTTFText ($image, getSize(), 0, 112, 190, getColour($image), $phpbb_root_path.getFont($fonts), $code[3]);
ImageTTFText ($image, getSize(), 110,  80, 140, getColour($image), $phpbb_root_path.getFont($fonts), $code[4]);
ImageTTFText ($image, getSize(), 40,  80, 100, getColour($image), $phpbb_root_path.getFont($fonts), $code[5]);
// Variation with Rotation
// ImageTTFText ($image, getSize(), getRotation(),  90, 50, getColour($image), $phpbb_root_path.getFont($fonts), $code[5]);

// ImageTTFText ($image, 12, 0, 0,  240, getColour($image), $phpbb_root_path.getFont($fonts), $codeorg);

// Ausgabe im Format PNG
ImagePng     ($image);

// Resourcen wieder freigeben
ImageDestroy ($image);

unset($image);
exit;

function getDirection()
{
   return mt_rand(0,1);
}

function getColour($image)
{
   return ImageColorAllocate ($image, mt_rand(0, 255),mt_rand(0, 255),mt_rand(0, 255));
}

function getRotation()
{
   return mt_rand(-90,90);
}

function getSize()
{
   return mt_rand(20,32);
}

function getFont($fonts)
{
   return '/captcha/'.$fonts[rand(0, (count($fonts)-1))];
}

?>
Example under: www.html-seminar.de/_forum/
Use it, have fun (an less spam)
Antworten

Zurück zu „phpBB 2.0: Mods in Entwicklung“