reCAPTCHA v2 PHP validation process

1,090 views
Skip to first unread message

Mario Lukačić

unread,
Sep 26, 2016, 8:50:42 AM9/26/16
to reCAPTCHA
Hi all, i wonder if this is a proper way to use reCAPTCHA v2 in my register.php script


<?php

include 'core/main.php';

if (isset($_POST['submit']))
{
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['repeat_pasword']) && isset($_POST['email']) && isset($_POST['g-recaptcha-response']))
{
$user = stripslashes(trim($_POST['username']));
$pass = stripslashes(trim($_POST['password']));
$pass2 = stripslashes(trim($_POST['repeat_pasword']));
$email = stripslashes(trim($_POST['email']));

if (!empty($user) && !empty($pass) && !empty($pass2) && !empty($email))
{

if (strlen($user) < 5)
{
$error[] = 'Username must be atleast 5 characters long.';
}
if ($users->user_exists($user))
{
$error[] = 'Username in use, please choose another one.';
}
if (strlen($pass) < 8) 
{
$error[] = 'Password must be atleast 8 characters long.';
}
if ($pass != $pass2)
{
$error[] = 'Passwords do not match.';
}
if ($users->email_exists($email))
{
$error[] = 'Email in use, please choose another one.';
}
if ($_POST['g-recaptcha-response'] == false)
{
$error[] = 'Please select captcha cube.';
}
if (empty($error))
{
// query

echo 'Ok register user'; // test
}

}
else
{
$error[] = 'All fields are required.';
}
}
}

?>


<h1>Register form</h1>

<?php

if (!empty($error))
{
foreach ($error as $key)
{
echo '<ul><li>'.$key.'</li></ul>';
}
}

?>

<form action="" method="post">
Username : <input type="text" name="username" maxlength="30"><br>
Password : <input type="password" name="password"><br>
Repeat password : <input type="password" name="repeat_pasword"><br>
Email : <input type="text" name="email"><br>
<div class="g-recaptcha" data-sitekey="my key"></div>
<input type="submit" name="submit" value="Register">
</form>


Mario Lukačić

unread,
Sep 27, 2016, 11:07:21 AM9/27/16
to reCAPTCHA
bump

Mario Lukačić

unread,
Sep 28, 2016, 10:47:37 AM9/28/16
to reCAPTCHA
bump

Seth Munroe

unread,
Sep 28, 2016, 11:39:18 AM9/28/16
to reCAPTCHA
You need to validate the value of g-recaptcha-respoonse by sending it to the validation url and evaluating the response.

Take a look at:

I don't work with php, but you could probably google something like php post request and php evaluate json response and find some code examples.

-Seth

Mario Lukačić

unread,
Sep 28, 2016, 12:23:45 PM9/28/16
to reCAPTCHA

Егор Правдин

unread,
Oct 1, 2016, 5:46:43 PM10/1/16
to reCAPTCHA
Hey morons and creators of reCAPTCHA, and I transcribe this kind fag captcha(FUCKthe correct answer (WOOD)
What a stupid logic of your mental retardation should be guided by an ordinary person(not a monkey, you) to solve your captcha porn,
Sincerely cocksucker holey

понедельник, 26 сентября 2016 г., 17:50:42 UTC+5 пользователь Mario Lukačić написал:
Reply all
Reply to author
Forward
0 new messages