Note: This is a historical reference, not a current security baseline. Magento 1 is end-of-life.

The following fatal PHP error is thrown in PHP 7.x on attempt to login to Magento Connect Manager / Downloader:

PHP Fatal error:  Uncaught DivisionByZeroError: Modulo by zero in downloader/Maged/BruteForce/Validator.php:59

Cause

Modulo by zero is used on line 59 of downloader/Maged/BruteForce/Validator.php when $configAttemptsCount is 0:
        $configAttemptsCount = $this->getConfigAttemptsCount();

        if ($badAttempts >= $configAttemptsCount and $badAttempts % $configAttemptsCount === 0) {

Solution

Add a check for non-zero $configAttemptsCount:
--- downloader/Maged/BruteForce/Validator.php
+++ downloader/Maged/BruteForce/Validator.php
@@ -56,7 +56,7 @@
         $badAttempts = $this->getBadAttempts();
         $configAttemptsCount = $this->getConfigAttemptsCount();
 
-        if ($badAttempts >= $configAttemptsCount and $badAttempts % $configAttemptsCount === 0) {
+        if ($configAttemptsCount > 0 and $badAttempts >= $configAttemptsCount and $badAttempts % $configAttemptsCount === 0) {
             $lastBadLogin = intval($this->model->get(self::MODEL_KEY_LAST_BAD_TIME));
             if ($lastBadLogin > 0) {
                 $timeDiff = $this->model->get(self::MODEL_KEY_DIFF_TIME_TO_ATTEMPT, self::DEFAULT_DIFF_TIME_TO_ATTEMPT);

Comments

Archived discussion

  1. Joey

    Thus worked for me.

    Remove the light blue coding located in downloader/Maged/BruteForce/Validator.php and paste in the yellow coding from above