|
5 | 5 | */
|
6 | 6 | namespace Magento\Captcha\Model;
|
7 | 7 |
|
| 8 | +use Magento\Framework\Math\Random; |
| 9 | + |
8 | 10 | /**
|
9 | 11 | * Implementation of \Zend_Captcha
|
10 | 12 | *
|
| 13 | + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) |
| 14 | + * |
11 | 15 | * @author Magento Core Team <core@magentocommerce.com>
|
12 | 16 | */
|
13 | 17 | class DefaultModel extends \Zend_Captcha_Image implements \Magento\Captcha\Model\CaptchaInterface
|
@@ -68,22 +72,30 @@ class DefaultModel extends \Zend_Captcha_Image implements \Magento\Captcha\Model
|
68 | 72 | */
|
69 | 73 | protected $_session;
|
70 | 74 |
|
| 75 | + /** |
| 76 | + * @var Random |
| 77 | + */ |
| 78 | + private $randomMath; |
| 79 | + |
71 | 80 | /**
|
72 | 81 | * @param \Magento\Framework\Session\SessionManagerInterface $session
|
73 | 82 | * @param \Magento\Captcha\Helper\Data $captchaData
|
74 | 83 | * @param \Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory
|
| 84 | + * @param Random $randomMath |
75 | 85 | * @param string $formId
|
76 | 86 | */
|
77 | 87 | public function __construct(
|
78 | 88 | \Magento\Framework\Session\SessionManagerInterface $session,
|
79 | 89 | \Magento\Captcha\Helper\Data $captchaData,
|
80 | 90 | \Magento\Captcha\Model\ResourceModel\LogFactory $resLogFactory,
|
81 |
| - $formId |
| 91 | + $formId, |
| 92 | + Random $randomMath = null |
82 | 93 | ) {
|
83 | 94 | $this->_session = $session;
|
84 | 95 | $this->_captchaData = $captchaData;
|
85 | 96 | $this->_resLogFactory = $resLogFactory;
|
86 | 97 | $this->_formId = $formId;
|
| 98 | + $this->randomMath = $randomMath ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Random::class); |
87 | 99 | }
|
88 | 100 |
|
89 | 101 | /**
|
@@ -361,23 +373,9 @@ public function setShowCaptchaInSession($value = true)
|
361 | 373 | */
|
362 | 374 | protected function _generateWord()
|
363 | 375 | {
|
364 |
| - $word = ''; |
365 |
| - $symbols = $this->_getSymbols(); |
| 376 | + $symbols = (string)$this->_captchaData->getConfig('symbols'); |
366 | 377 | $wordLen = $this->_getWordLen();
|
367 |
| - for ($i = 0; $i < $wordLen; $i++) { |
368 |
| - $word .= $symbols[array_rand($symbols)]; |
369 |
| - } |
370 |
| - return $word; |
371 |
| - } |
372 |
| - |
373 |
| - /** |
374 |
| - * Get symbols array to use for word generation |
375 |
| - * |
376 |
| - * @return array |
377 |
| - */ |
378 |
| - protected function _getSymbols() |
379 |
| - { |
380 |
| - return str_split((string)$this->_captchaData->getConfig('symbols')); |
| 378 | + return $this->randomMath->getRandomString($wordLen, $symbols); |
381 | 379 | }
|
382 | 380 |
|
383 | 381 | /**
|
|
0 commit comments