Posts Tagged ‘phpBB’

Use reCaptcha in phpBB3 tutorial protect automatic registration

Wednesday, January 28th, 2009

Some of my customers use phpBB3 forum and they started to get automated logins and their forums were hacked and some posts were written. I found interesting webpage about how to use reCaptcha with phpBB3 so i wrote this tutorial. It works with template prosilver and example pictures are also in prosilver.

At first you will need FREE reCAPTCHA PHP plugin /(recaptcha-php-1.10.zip – reCAPTCHA Library for PHP – v1.10), available at Google download reCAPTCHA Library for PHP. After that you will have to get public and private key for use with reCaptcha. Link: http://recaptcha.net/api/getkey

Extract the file ‘recaptchalib.php’ and place it in:
%phpbb_root_path%/includes/captcha

First we must modify code in template file (%phpbb_root_path%/styles/prosilver/template/ucp_register.html)

Locate code <dd>{CONFIRM_IMG}</dd> and delete the following lines of code or comment them out:
<dd><input type=”text” name=”confirm_code” id=”confirm_code” size=”8″
maxlength=”8″ class=”inputbox narrow” title=”{L_CONFIRM_CODE}” /></dd>
<dd>{L_CONFIRM_CODE_EXPLAIN}</dd>

Part code of File ucp_register.html will look like

Part code of File ucp_register.html will look like

In file %phpbb_root_path%/includes/ucp/ucp_register.php there will be more changes so lets get to it.

Step 1. Place  (add) code require_once($phpbb_root_path . ‘includes/captcha/recaptchalib.’ .
$phpEx);
before the line “class ucp_register,” which is almost on top of ucp_register.php file.

If your phpBB is on unix you should use server include_once(… instead of require_once(… (Typo was so friendly to let me know about errors in his log file when using this tutorial – and a solution to this problem).

Step 2. Place code

$publickey = ”;
$privatekey = ”;

$resp = null;
$error = null;

after the line “global $config, $db, $user,
$auth, $template, $phpbb_root_path, $phpEx;

Step 3. Place code $confirm_id = (isset($_POST['recaptcha_response_field'])); on the line “$confirm_id = request_var(’confirm_id’, ”);“. Simply replace code.

Edited code of ucp_register.php file

Edited code of ucp_register.php file

Step 4. Comment out or delete the following line of code ‘confirm_code’  => array(’string’, !$config['enable_confirm'], 5, 8),

Step 5. Go to the section

// Visual Confirmation handling

$wrong_confirm = false;

if (!$confirm_id)
{
$error[] = $user->lang['CONFIRM_CODE_WRONG'];
$wrong_confirm = true;
}
else
{

Delete all code within the first else statement (which has also nested if and else statements within it) and replace with next code:

$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],

$_POST["recaptcha_challenge_field"],

$_POST["recaptcha_response_field"]);

if ($resp->is_valid == false) {
$error[] = $user->lang['CONFIRM_CODE_WRONG'];
$wrong_confirm = true; }

Next step replace code in Visual confirmation handling

Next step replace code in Visual confirmation handling

Step 6. Comment out or delete everything between the following two
lines of code (including first ans last line (delete approx. 13 linex of php code):

First line of code: $code = gen_rand_string(mt_rand(5, 8));

Last line of code: $db->sql_query($sql);

Step 7. A few lines after the end of Step 6, replace “$confirm_image = ‘<img src=”‘ . append_sid(”{$phpbb_root_path}ucp.$phpEx”, ‘mode=confirm&amp;id=’ . $confirm_id . ‘&amp;type=’ . CONFIRM_REG . $str) . ‘” alt=”" title=”" />’;“with the following line of code: $confirm_image = recaptcha_get_html($publickey, $error);

Last changes of code in ucp_register.php

Last changes of code in ucp_register.php

Step 8. Upload both changed files in appropriate folder over ftp on your web server and don’t forget to flush cache in Administration panel of forum for templates – else it won’t work – something like: Templates – Themes – Refresh action.