diff --git a/doc/config.rst b/doc/config.rst index abd835e5e9..be516c105d 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1872,6 +1872,18 @@ Cookie authentication options bypass regular expression by the suffix, while connecting to another server. +.. config:option:: $cfg['CaptchaMethod'] + + :type: string + :default: ``'invisible'`` + + Valid values are: + + * ``'invisible'`` Use an invisible captcha checking method; + * ``'checkbox'`` Use a checkbox to confirm the user is not a robot. + + .. versionadded:: 5.0.3 + .. config:option:: $cfg['CaptchaLoginPublicKey'] :type: string diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php index a4835819f2..2e57ca4e53 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php +++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php @@ -250,9 +250,15 @@ class AuthenticationCookie extends AuthenticationPlugin } else { echo ''; - echo ''; + if (isset($GLOBALS['cfg']['CaptchaMethod']) && $GLOBALS['cfg']['CaptchaMethod'] === 'checkbox') { + echo '
'; + echo ''; + } else { + echo ''; + } } $_form_params = []; if (! empty($GLOBALS['target'])) { diff --git a/libraries/config.default.php b/libraries/config.default.php index 50401d7afd..7eef0e0711 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -835,6 +835,13 @@ $cfg['AllowArbitraryServer'] = false; */ $cfg['ArbitraryServerRegexp'] = ''; +/** + * To enable reCaptcha v2 checkbox mode if necessary + * + * @global string $cfg['CaptchaMethod'] + */ +$cfg['CaptchaMethod'] = 'invisible'; + /** * if reCaptcha is enabled it needs public key to connect with the service * diff --git a/test/classes/Plugins/Auth/AuthenticationCookieTest.php b/test/classes/Plugins/Auth/AuthenticationCookieTest.php index 5291d44a1c..0af2e45cb1 100644 --- a/test/classes/Plugins/Auth/AuthenticationCookieTest.php +++ b/test/classes/Plugins/Auth/AuthenticationCookieTest.php @@ -351,6 +351,91 @@ class AuthenticationCookieTest extends PmaTestCase ); } + /** + * Test for PhpMyAdmin\Plugins\Auth\AuthenticationConfig::showLoginForm + * + * @return void + * @group medium + */ + public function testAuthCaptchaCheckbox() + { + $mockResponse = $this->mockResponse(); + + $mockResponse->expects($this->once()) + ->method('isAjax') + ->with() + ->will($this->returnValue(false)); + + $mockResponse->expects($this->once()) + ->method('getFooter') + ->with() + ->will($this->returnValue(new Footer())); + + $mockResponse->expects($this->once()) + ->method('getHeader') + ->with() + ->will($this->returnValue(new Header())); + + $_REQUEST['old_usr'] = ''; + $GLOBALS['cfg']['LoginCookieRecall'] = false; + + $GLOBALS['pmaThemeImage'] = 'test'; + $GLOBALS['cfg']['Lang'] = ''; + $GLOBALS['cfg']['AllowArbitraryServer'] = false; + $GLOBALS['cfg']['Servers'] = [1]; + $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = 'testprivkey'; + $GLOBALS['cfg']['CaptchaLoginPublicKey'] = 'testpubkey'; + $GLOBALS['cfg']['CaptchaMethod'] = 'checkbox'; + $GLOBALS['server'] = 0; + + $GLOBALS['error_handler'] = new ErrorHandler(); + + ob_start(); + $this->object->showLoginForm(); + $result = ob_get_clean(); + + // assertions + + $this->assertStringContainsString('id="imLogo"', $result); + + // Check for language selection if locales are there + $loc = LOCALE_PATH . '/cs/LC_MESSAGES/phpmyadmin.mo'; + if (is_readable($loc)) { + $this->assertStringContainsString( + '