hackzilla / password-generator

PHP Library to generate random passwords
https://hackzilla.org
MIT License
293 stars 37 forks source link

[Insight] Usage of a function in loops should be avoided - in Generator/HybridPasswordGenerator.php, line 116 #2

Closed hackzilla closed 10 years ago

hackzilla commented 10 years ago

in Generator/HybridPasswordGenerator.php, line 116

This loop uses a function. To avoid the overhead of executing the function n times, you should precalculate it before the loop.

        for ($i = 0; $i < $this->_segmentCount; $i++) {
            if ($password) {
                $password .= $this->getSegmentSeparator();
            }

            for ($j = 0; $j < $this->getSegmentLength(); $j++) {
                $password .= $characterList[mt_rand(0, $characters - 1)];
            }
        }

        return $password;

Posted from SensioLabsInsight