Magento 2 : CAPTCHA image display too much dots
-
14-04-2021 - |
Question
I'm new in magento. I am working in custom module.
I apply captcha in registration page and login page. But, there are too much dots and lines display in image. Sometimes, I can't read text properly.
I checked in admin configuration. But, I didn't found any configuration to decrease dots and lines from CAPTCHA.
How to do manage this?
please help me to solve this issue.
Thanks.
Solution
Go to :
/vendor/magento/zendframework1/library/Zend/Captcha/Image.php
Open this file and go to line no 121 and 129.
Find this below line :
protected $_dotNoiseLevel = 100; // For dots
protected $_lineNoiseLevel = 5; // For lines
And replace it :
protected $_dotNoiseLevel = 50;
protected $_lineNoiseLevel = 3;
Save it and clean cache.
OTHER TIPS
Tested in Magento 2.2
The DotNoiseLevel and LineNoiseLevel are set in vendor\zendframework\zend-captcha\src\Image.php
You can override Magento\Captcha\Model\DefaultModel
and set DotNoiseLevel and LineNoiseLevel as class DefaultModel extends \Zend\Captcha\Image
Your Custom module di.xml will be
<preference for="Magento\Captcha\Model\DefaultModel" type="Custom\Captcha\Model\DefaultModel"/>
and model class will be Custom\Captcha\Model\DefaultModel.php
public function __construct(
\Magento\Framework\Session\SessionManagerInterface $session,
\Magento\Captcha\Helper\Data $captchaData,
\Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory,
$formId
) {
parent::__construct($session,$captchaData,$resLogFactory,$formId);
$this->setDotNoiseLevel(2);
$this->setLineNoiseLevel(1);
}
/vendor/magento/zendframework1/library/Zend/Captcha/Image.php (nothing will happen after change so go below path)
/vendor/zendframework/zend-captcha/src/Image.php
Open this file and go to line no 106 and 114.
Find this below line :
protected $_dotNoiseLevel = 100; // For dots protected $_lineNoiseLevel = 5; // For lines And replace it :
protected $_dotNoiseLevel = 0; protected $_lineNoiseLevel = 0;