Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

->passes() and ->fails() both return true simultaneously #45

Closed
jmp909 opened this issue Aug 30, 2016 · 3 comments
Closed

->passes() and ->fails() both return true simultaneously #45

jmp909 opened this issue Aug 30, 2016 · 3 comments
Labels

Comments

@jmp909
Copy link

jmp909 commented Aug 30, 2016

$captchaValidator = \Validator::make(Input::all(), ['g-recaptcha-response' => 'required|captcha']);
echo("passes:" .$captchaValidator->passes(). ", fails:".$captchaValidator->fails());

both return 1.

I can just check ->passes() to get around it, but ->fails() should not return 1?

maybe related to:
#38

thanks
j

@jmp909
Copy link
Author

jmp909 commented Aug 30, 2016

calling ->passes() twice gives false on second result

echo($captchaValidator->passes()); // true
echo($captchaValidator->passes()); // false  (->fails() would be true here therefore)

@anhskohbo
Copy link
Owner

Humm, maybe by fault of laravel validator. I try test with required rule and add var_dump(1) in Illuminate\Validation\Validator::validateRequired and get same error.

I will try to ask the laravel/framework see why!

Thanks for report!

@anhskohbo anhskohbo added the bug label Sep 3, 2016
@dharmavir
Copy link

dharmavir commented Oct 14, 2016

It's not Laravel validator. I ran tests outside Laravel and found that when you validate same response ('g-recaptcha-response') after initial success, all other attempts will return success false.

$VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
$peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
$query['secret'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$query['response'] = $_POST['g-recaptcha-response'];

$context = stream_context_create(array(
    'http' => array(
        'header' => "Content-type: application/x-www-form-urlencoded\r\n",
        'method' => 'POST',
        'content' => http_build_query($query, '', '&'),
        'verify_peer' => true,
        $peer_key => 'www.google.com',
    ),
));
$response = file_get_contents($VERIFY_URL, false, $context);
print_r(json_decode($response, true));  
/* Array
(
    [success] => 1
    [challenge_ts] => 2016-10-14T19:13:07Z
    [hostname] => localsecure.example.com
) */

$response = file_get_contents($VERIFY_URL, false, $context);
print_r(json_decode($response, true));
/* Array
(
    [success] => 
    [challenge_ts] => 2016-10-14T19:13:07Z
    [hostname] => localsecure.example.com
) */

$response = file_get_contents($VERIFY_URL, false, $context);
print_r(json_decode($response, true)); // sucess = 
/* Array
(
    [success] => 
    [challenge_ts] => 2016-10-14T19:13:07Z
    [hostname] => localsecure.example.com
) */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants