Out of curiosity, I was going through the captcha module of M2 and I noticed this interesting code in Magento/Captcha/Helper/Data.php

public function getCaptcha($formId)
    if (!array_key_exists($formId, $this->_captcha)) {
        $captchaType = ucfirst($this->getConfig('type'));
         if (!$captchaType) {
             $captchaType = self::DEFAULT_CAPTCHA_TYPE;
          } elseif ($captchaType == 'Default') {
               $captchaType = $captchaType . 'Model';
          $this->_captcha[$formId] = $this->_factory->create($captchaType, $formId);
    return $this->_captcha[$formId];

So that code seems pretty clear to me. Magento 2 is shipped with a default captcha with the associated model being Magento/Captcha/Model/DefaultModel

That model implements the Magento/Captcha/Model/CaptchaInterface with the following methods:

public function generate();
public function isCorrect($word);
public function getBlockName();

I can see that the dev team made the code flexible enough to implement your own captcha type which is great.

So I assume that if one wants to implement its own type of captcha he will have to create a captcha model that implements that interface.

My question is: apart from the model creation, what do we need to do to implement a custom captcha type (specially in terms of configuration, pretty sure there's some XML going on here I was expecting a captcha.xml to sit somewhere but there's none)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.