One of the main requirements for online shopping is its security, so any online store must be built on a secure e-commerce platform. When it comes to reliable and secure platforms, Magento must be mentioned. At the same time, in order to make the store really safe, you need to follow certain recommendations. One of them is the use of reCAPTCHA. Magento developers recently announced that reCAPTCHA and 2FA functionality has been added to all Magento 2.1 versions. So, we will show you how to set up reCAPTCHA in Magento 2.
Method 1 of 3: Setting up reCAPTCHA in Magento 2
Step 1. Launch an SSH terminal
Connect Magento 2 store and go to root directory. Step 2. Run the following command:
composer require msp / recaptcha: 2.0.0
You will be prompted for the repository credentials, username and password, which you can get for your account.
If you get the error message ‘proc_open (): fork failed - Cannot allocate memory’ in phar, then you can resolve it by enabling Swap space or by running the following command:
php -d memory_limit = -1 / usr / local / bin / composer require msp / recaptcha: 2.0.0
Step 3. Enable the module by running the following command:
php bin / magento module: enable --all
Then update the setting with the command:
php bin / magento setup: upgrade Step 4. Now clear the cache:
php bin / magento cache: clean
php bin / magento cache: flush
Method 2 of 3: Generating Google reCAPTCHA Keys
Step 1. Go to the Google reCAPTCHA site
Make sure you are signed in to your account.
Step 2. Enter a label for the keys
The example uses the label "My Magento CAPTCHA"; you can add your own variant. Then select the reCAPTCHA type. There are three types of reCAPTCHAs available here, and here's what two of them do:
- reCAPTCHA v2 validates requests on the click of a button.
- Invisible reCAPTCHA validates requests in the background without any interaction.
Step 3. After selecting the CAPTCHA type, enter the Magento domain and subdomains to which you want to add the reCAPTCHA
Step 4. Accept the reCAPTCHA terms of service
To do this, check the box next to “Accept the reCAPTCHA Terms of Service” and then simply click “Register”. After that, you will be taken to a new page.
Step 5. Go to the “Adding reCAPTCHA to your site” section
You will see that the reCAPTCHA keys have been generated. Copy the Site Key and Secret Key that you will use next.
Method 3 of 3: Configuring Magento 2 reCAPTCHA
Step 1. Go to your store admin panel
In it, go to STORES → Configuration. Step 2. Click on "Google reCaptcha" in the Security tab.
Step 3. Expand the General section
Enter the Google reCaptcha keys you copied in the last step: Site Key - in the Google API website key and Secret Key - in the Google API secret key.
Step 4. Expand the "Backend" section
If you want to enable Google reCAPTCHA in the administrator login, select Yes from the “Enable” drop-down list.
Step 5. Expand the last section, "Frontend"
Select “Yes” from the “Enable” drop-down list.
- Then install Google reCaptcha for your external forms as per your needs.
Step 6. Click “Save Config”
Step 7. Go to any form page of your store
For example, the illustration shows a Contact Us page. You will see the result.