MyBB Community Forums

Full Version: [Deprecated since MyBB 1.8.4] noCaptcha with MyBB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
WARNING! And over again. This tutorial require core edits inside class_captcha.php file.

Well. noticed info above?
So let's start.

1. Make template edit.
Find member_register_regimage_recaptcha (let me help you. Is located at Member Templates).
Find:
<script type="text/javascript" src="{$server}/challenge?k={$public_key}"></script>

And replace it with:
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="{$public_key}"></div>

2. Make core file edit.
I think best solution would be telling which line of code were replaced. so:
At line 283 (as of latest commited file) find:
283. $challenge = $mybb->input['recaptcha_challenge_field'];
284. $response = $mybb->input['recaptcha_response_field'];
[[285 --> 327]]
328. $answer = explode("\n", $response[1]);
329. if(trim($answer[0]) != 'true')
330. {
331. // We got it wrong! Oh no...
332. $this->set_error($lang->invalid_captcha_verify);
333. }
334. }
335. }
336. }

And replace everything with:
$response = $mybb->input['g-recaptcha-response'];

if(!$response || strlen($response) == 0) {
	$this->set_error($lang->invalid_captcha);
} else {
	$google_url = "https://www.google.com/recaptcha/api/siteverify";
	$url = $google_url."?secret=".$mybb->settings['captchaprivatekey']."&response=".$response."&remoteip=".$session->ipaddress;
                
	$nocaptchareply = @file_get_contents($url);

	$res = json_decode($nocaptchareply, true);
	if(!$res['success']) {
		$this->set_error($lang->invalid_captcha_verify);
	}
}

3. Language edits (OBSOLETE):
go to your member.lang.php and find:
$l['verification_note'] = "Please enter the text contained within the image into the text box below it. This process is used to prevent automated processes.";
[....]
$l['error_regimageinvalid'] = "The image verification code that you entered was incorrect. Please enter the code exactly how it appears in the image.";
$l['error_regimagerequired'] = "Please fill out the image verification code to continue the login process. Please enter the code exactly how it appears in the image.";

And edit them as you'd like to be appared. For example:

$l['verification_note'] = "Please checkbox a square. This process is used to prevent automated processes.";
[....]
$l['error_regimageinvalid'] = "Please click the checkbox.";
$l['error_regimagerequired'] = "Something went wrong. Please retry again.";

And that's all Smile
More info about noCaptcha can be found [here] and [here]

Edit: This tutorial will be deprecated (as of MyBB Developers included noCaptcha in next release).
Hi,
Thank you for the tutorial! I'll not use it yet because I do not want to edit core files.

I'll also add a video that can help people that don't know what noCaptcha is. Smile

(2014-12-05, 02:16 AM)YOLOnline Wrote: [ -> ]I'll not use it yet because I do not want to edit core files.

Hi... you dont necessarily need to edit any core files... first add the noCaptcha api script in your header

<script src='https://www.google.com/recaptcha/api.js'></script>

and then edit the member_register template and replace {$regimage} with the noCaptcha..

<div class="g-recaptcha" data-sitekey="YOUR SITE KEY FROM GOOGLE"></div>
it should work.....
(2014-12-05, 06:50 AM)mmadhankumar Wrote: [ -> ]
(2014-12-05, 02:16 AM)YOLOnline Wrote: [ -> ]I'll not use it yet because I do not want to edit core files.

Hi... you dont necessarily need to edit any core files... first add the noCaptcha api script in your header


<script src='https://www.google.com/recaptcha/api.js'></script>

and then edit the member_register template and replace {$regimage} with the noCaptcha..


<div class="g-recaptcha" data-sitekey="YOUR SITE KEY FROM GOOGLE"></div>
it should work.....

It wont. Because:
1. is different api
2. queries different inputs
3. is $_GET (not $_POST)
I did what u asked but didn't work on my forum and I don't know why ?
They are implementing this on core in 1.8.4 see here http://community.mybb.com/thread-163770.html
I was faster \O/
if i do this in 1.8.3 will i have any problems at time of updating to update 1.8.4?
(2015-01-13, 09:47 AM)Hamster24 Wrote: [ -> ]if i do this in 1.8.3 will i have any problems at time of updating to update 1.8.4?

No. but since 1.8.4 have it i'd suggest to upgrade to get better working noCaptcha (i was using static php functions instead of mybb's one)