RoundCube – Enable recapcha on login

RoundCube – Enable recapcha on login
Photo by erica steeves / Unsplash

We connect to the console and go to the folder with attachments in roundcube:

cd ../plugins/

Cloning the google captcha plugin repository:

git clone https://github.com/dsoares/rcguard.git rcguard

Don’t forget to set the correct owner and user, for example:

chown -R www-data:www-data rcguard

Go to plugin folder:

cd rcguard

Change the config:

cp config.inc.php.dist config.inc.php
nano config.inc.php

In the next lines we write the keys:

// reCAPTCHA site key
$config['recaptcha_publickey'] = '';

// reCAPTCHA secret key
$config['recaptcha_privatekey'] = '';

Keys can be obtained from this link.: https://www.google.com/recaptcha/admin/

In the next line we can specify the captcha version (v2 or v3):

$config['recaptcha_api_version'] = 'v3';

In the next line, we write the number of incorrect authorization attempts after which the captcha is displayed, if necessary, always leave “0”:

$config['failed_attempts'] = 0;

Next, we have to create a table in the roundcube database with the following query:

CREATE TABLE `rcguard` (
  `ip` VARCHAR(40) NOT NULL,
  `first` DATETIME NOT NULL,
  `last` DATETIME NOT NULL,
  `hits` INT(10) NOT NULL,
  PRIMARY KEY (`ip`),
  INDEX `last_index` (`last`),
  INDEX `hits_index` (`hits`)
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;

Can be done through the Mysql console or through PhpMyAdmin. If you use a database prefix – do not forget to include it in the table name – rcguard.

Next, in the config of the roundcube itself, we connect the plugin by editing the line:

$config['plugins'] = array();

Change to:

$config['plugins'] = array('rcguard');

Checking the captcha on the site.