No Code Attached Yet
avatar akbet1
akbet1
2 Mar 2020

Hello

Steps to reproduce the issue

Create recapctha with help PHP in VIEw:

    $captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request' ));
    echo $captcha->display('recaptcha', 'recaptcha', 'required');

Check recapctha result in controller, with help PHP:

    $captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request'));
    if($captcha){
         $answer = $captcha->checkAnswer('captcha_keystring_rent_request'); <-- there exception: Google return "invalid-input-response" 
         if(!$answer) {
               //show error, "bad filled captcha"
               exit();
         }
    }

Expected result

Until Joomla 3.9.15, this code work good (include Joomla 3.9.14)

Actual result

Now we receive exception from Google.

System information (as much as possible)

Joomla 3.9.15.
reproduce on many PC, keys in recaptcha plugin are good.
In Joomla registration recaptcha works good
Please check attachment

Additional comments

Regards
Andrew!
screen shot 2020-03-02 at 19 43 09

avatar akbet1 akbet1 - open - 2 Mar 2020
avatar joomla-cms-bot joomla-cms-bot - labeled - 2 Mar 2020
avatar brianteeman brianteeman - change - 2 Mar 2020
Priority Critical Medium
avatar joomla-cms-bot joomla-cms-bot - edited - 2 Mar 2020
avatar brianteeman
brianteeman - comment - 2 Mar 2020

reset priority according to our published guides


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.

avatar Fedik
Fedik - comment - 2 Mar 2020

what captcha plugin is enabled?
recaptcha should work

however recaptcha_invisible has a bug in plugin implementation, the plugin ignores $code at all

*/
public function onCheckAnswer($code = null)
{
$input = \JFactory::getApplication()->input;
$privatekey = $this->params->get('private_key');
$remoteip = IpHelper::getIp();
$response = $input->get('g-recaptcha-response', '', 'string');
// Check for Private Key
if (empty($privatekey))

avatar SharkyKZ
SharkyKZ - comment - 2 Mar 2020

It's Recaptcha. Since #26882 it makes use of $code argument. It seems correct to me as well, but causes issues when passing whatever to checkAnswer() like in this case.

If we keep it as, @akbet1, you'll have to solve it on your end by removing erroneous argument or by passing the actual answer, e.g.

$answer = $captcha->checkAnswer();
avatar akbet1
akbet1 - comment - 3 Mar 2020

Hi

@Fedik
If I check joomla-cms/plugins/captcha/recaptcha_invisible/recaptcha_invisible.php
in joomla 3.9.15
I see there code exactly as you propose use
But we use "recaptcha", we not use "recaptcha_invisible"

@SharkyKZ
we use
$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request'));
$answer = $captcha->checkAnswer('captcha_keystring_rent_request');

"captcha_keystring_rent_request" - it need because we have 2 forms on page, so we need check which captcha user press.

If I try use:
$answer = $captcha->checkAnswer();

I see next error:
Too few arguments to function Joomla\CMS\Captcha\Captcha::checkAnswer(), 0 passed in /home/windsorh/public_html/components/com_realestatemanager/realestatemanager.php on line 945 and exactly 1 expected
File: /home/windsorh/public_html/libraries/src/Captcha/Captcha.php
Line: 177

Regards


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.
avatar Fedik
Fedik - comment - 3 Mar 2020

okay, then what exactly is 'captcha_keystring_rent_request', and how you get it?

avatar akbet1
akbet1 - comment - 3 Mar 2020

As I believe (before), it is namespace, we use it at time show captcha:

$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request' ));
echo $captcha->display('recaptcha', 'recaptcha', 'required');

so on 1 page we may have 2 captha, as example for show second captcha we use:

$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_review' ));
echo $captcha->display('recaptcha', 'recaptcha', 'required');

'captcha_keystring_review' - another namespace

Regards


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.
avatar SharkyKZ
SharkyKZ - comment - 3 Mar 2020

It's supposed to be the answer.

* @param string $code The answer.
*
* @return bool Whether the provided answer was correct
*
* @since 2.5
* @throws \RuntimeException
*/
public function checkAnswer($code)

avatar Fedik
Fedik - comment - 3 Mar 2020

'captcha_keystring_review' - another namespace

that incorrect,
$captcha->checkAnswer($code); the $code supposed to be a token, answer from recpatcha api on client side

avatar Fedik
Fedik - comment - 3 Mar 2020

@SharkyKZ was faster ?

avatar akbet1
akbet1 - comment - 3 Mar 2020

Thank you!
but will be best if you provide "how to", and not only hints, some like:
show captcha:

$captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_rent_request' ));
echo $captcha->display('recaptcha', 'recaptcha', 'required');

check captcha:

    //Check enabled plugin captcha-recaptcha
    $recaptchaPluginEnabled = JPluginHelper::isEnabled('captcha', 'recaptcha');

    //Check enable option captcha-recaptcha in admin form
    $app = JFactory::getConfig();
    $recaptchaAdminEnabled = false;
    if($app->get('captcha') == 'recaptcha'){
      $recaptchaAdminEnabled = true;
    }

            if( $googleRecaptchaEnabled && $recaptchaPluginEnabled ){
                $captcha = JCaptcha::getInstance('recaptcha', array('namespace' => 'captcha_keystring_buy_request'));

                if($captcha){
                    $get_answer = JFactory::getApplication()->input->get("g-recaptcha-response", "");
                    $answer = $captcha->checkAnswer($get_answer);
                       //check captcha
                        if(!$answer ) {
                        //captcha check error
                        exit();
                    }
                }
            }

Regards


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.

avatar akbet1
akbet1 - comment - 3 Mar 2020

if( $googleRecaptchaEnabled && $recaptchaPluginEnabled ){

need replace to
if( $recaptchaPluginEnabled && $recaptchaAdminEnabled ){


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.

avatar akbet1
akbet1 - comment - 3 Mar 2020

but !!!!!!
How this worked in joomla 3.9.14 and before ?!!!
without:
$get_answer = JFactory::getApplication()->input->get("g-recaptcha-response", "");

Regards


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.

avatar richard67
richard67 - comment - 3 Mar 2020

@akbet1 @SharkyKZ has already provided the answer above #28191 (comment):

It's Recaptcha. Since #26882 it makes use of $code argument. It seems correct to me as well, but causes issues when passing whatever to checkAnswer() like in this case.

PR #26882 was merged end of December last year, this explains that there is a difference between 3.9.14 and 3.9.15.

avatar akbet1
akbet1 - comment - 4 Mar 2020

Hi
But continue this not good, as me seem, you may give possibility run
$answer = $captcha->checkAnswer(); <-- without argumenets

and in plugin, if call with "$code = null", you need add code like below:

public function onCheckAnswer($code = null)
{
$input = \JFactory::getApplication()->input;
$privatekey = $this->params->get('private_key');
if( $code == null) $code = $input->get("g-recaptcha-response", "");

Regards

avatar akbet1
akbet1 - comment - 4 Mar 2020

But, Thank you for your support !!!

avatar SharkyKZ
SharkyKZ - comment - 4 Mar 2020

There is already code like that in Recaptcha plugin:

$response = $code ? $code : $input->get('g-recaptcha-response', '', 'string');

If code is not provided, g-recaptcha-response input variable is used.

avatar akbet1
akbet1 - comment - 5 Mar 2020

Sorry,
Bur As I wrote:

If I try use:
$answer = $captcha->checkAnswer();

I see next error:
Too few arguments to function Joomla\CMS\Captcha\Captcha::checkAnswer(), 0 passed in /home/windsorh/public_html/components/com_realestatemanager/realestatemanager.php on line 945 and exactly 1 expected
File: /home/windsorh/public_html/libraries/src/Captcha/Captcha.php
Line: 177

Regards


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28191.

avatar SharkyKZ
SharkyKZ - comment - 5 Mar 2020

You're right. It can't be omitted. So it should be either the answer or null.

avatar joomdonation joomdonation - change - 16 Nov 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-11-16 09:00:19
Closed_By joomdonation
Labels Added: No Code Attached Yet
Removed: ?
avatar joomdonation joomdonation - close - 16 Nov 2022
avatar joomdonation
joomdonation - comment - 16 Nov 2022

More than 2 years later, I guess the author solved this issue base on the suggested code provided by @SharkyKZ in earlier comment. So I'm closing this issue. If you still need help (I don't think so), feel free to re-open.

Add a Comment

Login with GitHub to post a comment