Magento 2 Tutorials

How to Setup Magento 2 reCAPTCHA

Magento 2 reCAPTCHA

The security of any ecommerce store is crucial since nowadays customers prefer secured platforms for buying goods online. So, if you keep security on top of your mind, then your store must be built on a secured ecommerce platform. When you talk about reliable and secured ecommerce platforms, then you can’t neglect Magento from the list.

However, to make your Magento 2 store secure, you have to follow the best practices and reCAPTCHA is one of them. Last month Magento has made an announcement that reCAPTCHA and 2FA functionality has been added to all Magento 2.1 and above versions which is a great addition.

So, today in this guide, I am going to teach you how to configure Magento 2 reCAPTCHA. If you are using Magento 1.x version, then you can check this guide: How to Add Magento reCAPTCHA.

Let’s start!

Steps to Follow

Install Magento 2 reCAPTCHA

Launch the SSH terminal. connect your Magento 2 store and go to its root directory.

Now run the following command:

composer require msp/recaptcha:2.0.0

Then it will ask about repo credentials, username, and password which you can get by going to your marketplace account.

If you get an error ‘proc_open(): fork failed – Cannot allocate memory’ in phar then you can solve it by enabling Swap space or you can also solve it by running the following command:

php -d memory_limit=-1 /usr/local/bin/composer require msp/recaptcha:2.0.0

Once it’s done, enable the module by running this command:

php bin/magento module:enable –all

Then upgrade the setup with this command:

php bin/magento setup:upgrade

Now just clean and flush the cache:

php bin/magento cache:clean

php bin/magento cache:flush

Generate Google reCAPTCHA Keys for your Magento 2 Store

Go to Google reCAPTCHA site and make sure that you’re logged in to your account.

Now first enter the label for the keys, I have entered My Magento CAPTCHA, you can add one of your choice. Then choose the type of reCAPTCHA, here three types of reCAPTCHA are available and two of them are:

  1. reCAPTCHA v2: It validates requests with a button click.
  2. Invisible reCAPTCHA: It will validate requests in the background without any interaction.

label for google recaptcha keys

After selecting the CAPTCHA type,  enter your Magento store domain and subdomains on which you want to add reCAPTCHA:

google recaptcha add domains

Now click the checkbox that you accept the reCAPTCHA terms of service and then just click on Register:

register google recaptcha

You will be redirected to the new page, go to Adding reCAPTCHA to your site section and you will see that the reCAPTCHA keys are generated. Copy Site Key and Secret Key which you have to use in the next step.

Adding reCAPTCHA to your site

Configure Magento 2 reCAPTCHA

Go to the admin panel of your store and navigate to STORES Configuration:

stores - config magento 2 recaptcha

Now click on Google reCaptcha under Security tab:

google recaptcha security

First unfold the General section, enter the Google reCaptcha keys which you have copied in the last step. Site Key in Google API website key and Secret Key in Google API secret key:

General section magento 2 recaptcha

Unfold the backend section and if you want to enable Google reCAPTCHA in the admin login, then select Yes from Enable drop-down:

backend section Magento 2 recaptcha

Now unfold the last section, frontend. Select Yes from the Enable drop down and then set Google reCaptcha for your frontend forms according to your need:

frontend magento 2 recaptcha

frontend magento 2 recaptcha 2

At last, just click on Save Config:

save config magento 2 recaptcha

Now go to your any form page of your store, I am going to the contact page and here’s the result:

magento 2 recaptcha result

This above output indicates that Magento 2 reCAPTCHA is successfully configured.

Final Words

Your store might be fully optimized in all aspects, but if it lacks the rock-solid security which your customers demand, then you can lose the trust of your customers and see conversion rates fall. After following this guide, I hope you can now setup Magento 2 reCAPTCHA. As there are many security practices of Magento 2 store being implemented every day, adding reCAPTCHA is one of them. In the next tutorial, I will show you the method of configuring Two Factor authentication in Magento 2.

If you still have any confusion or query, related to this tutorial just leave your comment and I will get back to you asap!

 

Subscribe Newsletter

Subscribe to get latest Magento news

40% Off for 4 Months on Magento Hosting + 30 Free Migration