Magento 2 – How to Override Captcha Library Class

captchamagento-2.1magento2

With reference to my own question, I have found that we can change density and number of lines and dots in native magento 2 captcha in /vendor/magento/zendframework1/library/Zend/Captcha/Image.php.

Now my question is that how can we override above file class using custom module, because we don't want to make changes directly in core magento files.

Any help would be appreciated.

Thanks

Best Answer

It is not so complicated. First in composer.json file add this line in psr-0 node

"Zend_Captcha": "app/code/"

so it will look like that

"psr-0": {
   "": "app/code/",
   "Zend_Captcha": "app/code/"
},

Then create directory app/code/Zend/Captcha/ and place there your file Image.php that you want to override.

After that just run composer update.

Related Topic