reCaptcha on Signup/Login Page

Post about your customizations to share with others.

Moderators: Developer, Contributor

Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

reCaptcha on Signup/Login Page

Post by Mythotical »

I'm trying to implement a reCaptcha v2 Checkbox on my Signup/Login page. I have tried both methods on this page: https://developers.google.com/recaptcha/docs/display but the field doesn't show. See the attached image. I'm wondering if I'm doing something wrong. I have implemented this on other PHP software through plugins but I can't figure out why it won't show.
GoblinBot_Issue_Tracker.png
GoblinBot_Issue_Tracker.png (45.23 KiB) Viewed 7844 times
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: reCaptcha on Signup/Login Page

Post by cas »

There is a standard setting within Mantis:
/**
* use captcha image to validate subscription it requires GD library installed
* @global integer $g_signup_use_captcha
*/
$g_signup_use_captcha = ON;

So it is available, no need to change code for that.
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

I don't care for the built-in one as I've had people complain that they have entered the captcha correctly and it still gives an error so I would rather use reCaptcha and why MantisBT doesn't use reCaptcha instead of a custom built one beats me.
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: reCaptcha on Signup/Login Page

Post by cas »

In principle you should do this via a plugin but otherwise i would follow this:
http://acmeextension.com/integrate-goog ... -with-php/
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

cas wrote: 27 Aug 2020, 11:21 In principle you should do this via a plugin but otherwise i would follow this:
http://acmeextension.com/integrate-goog ... -with-php/
I always do things this way, edit files to see what needs to be replaced via plugin then put it all back to normal and start building the files to replace code in the files via a plugin. Thanks for the link, I'll check it out and report back.
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

I checked it out, reset the pages back to the original format, and tried just adding reCaptcha v2 Checkbox with MantisBT Captcha set to OFF and I put the field outside the if condition. Still not showing and I don't understand why it's not showing.
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: reCaptcha on Signup/Login Page

Post by cas »

Do you already have a valid key?
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: reCaptcha on Signup/Login Page

Post by cas »

It has some something to do with "noscript" tags used by recaptcha
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

cas wrote: 27 Aug 2020, 13:49 Do you already have a valid key?
Yes, I do.
cas wrote: 27 Aug 2020, 14:20 It has some something to do with "noscript" tags used by recaptcha
I see no "noscript" tags being used by reCaptcha.
cas
Posts: 1586
Joined: 11 Mar 2006, 16:08
Contact:

Re: reCaptcha on Signup/Login Page

Post by cas »

I tried another method which used those tags but also with the other solutions I face the same issue as you.
Check out what they write here:
https://stackoverflow.com/questions/308 ... ot-showing
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

cas wrote: 27 Aug 2020, 15:00 I tried another method which used those tags but also with the other solutions I face the same issue as you.
Check out what they write here:
https://stackoverflow.com/questions/308 ... ot-showing
Thanks looking into it. About to start a new thread about using my plugin to replace code in a specific page.
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

I did some tests on a completely new page I created called testload.php where I added everything and a test form. It all displays and shows correctly, I even added a script call before </head> making the google api call second to last and it still worked. So I'm wondering if there is something on the signup_page.php that is causing it to not load. Any suggestions?
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

Update: I tried implementing hCaptcha and still have the same issue with the box not showing at all and I can't figure out what could be interfering to make it not show.
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

UPDATE AGAIN: I think I found my problem and that is with content security policy so can someone let me know if I'm doing this right.

Code: Select all

    function hooks(){
        return array(
            "EVENT_CORE_HEADERS" => 'csp_headers',
            "EVENT_LAYOUT_RESOURCES" => 'scripts'
        );
    }
    
    function csp_headers() {
        http_csp_add( 'script-src', "https://hcaptcha.com" );
        http_csp_add( 'script-src', "https://*.hcaptcha.com");
        http_csp_add( 'image-src', "https://hcaptcha.com");
        http_csp_add( 'image-src', "https://*.hcaptcha.com");
        http_csp_add( 'style-src', "https://hcaptcha.com");
        http_csp_add( 'style-src', "https://*.hcaptcha.com");
    }
I'm not even sure that is working because the captcha box still isn't showing. The space for it is now there like the box is showing but there is nothing sooo appreciate all the help.
Mythotical
Posts: 21
Joined: 24 Aug 2020, 21:47
Contact:

Re: reCaptcha on Signup/Login Page

Post by Mythotical »

Final update: After hours of digging and testing, this thread https://www.mantisbt.org/bugs/view.php?id=14679 had the answer. It was CSP blocking it from loading. Once I added the sites to CSP, it loaded and works. Now to figure out where it calls to insert the user so it can check for captcha before inserting the user into the database.
Post Reply