mt_rand is not random enough
From reporter:
protected function generate() {
$characters = '123456789abcdefghijklmnpqrstuvwxyz';
$numChars = strlen($characters);
$string = '';
for ($p = 0; $p < $this->codeLength; $p++) {
do {
$n = ord(drupal_random_bytes(1));
} while ($n >= 238); // 238 = 256 - 256 % $numChars
$string .= $characters[$n % $numChars];
}
return $string;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2332445-tfa-fix-generate.patch | 583 bytes | coltrane |
| #1 | 2332445-tfa-random.patch | 855 bytes | coltrane |
Comments
Comment #1
coltraneComment #3
coltraneComment #5
jerebe commentedHi,
I've just tried your latest patch and i encounter some issue implementing it.
On this line :
while(strlen($string <= $this->codeLength));
however
strlen($string <= $this->codeLength) return 1 since you are comparing a string and an integer and generates infinite loop.
A quick fix could be : while(strlen($string) <= $this->codeLength);
Regards
Comment #6
DanielFbrg commented+1 confirmed
Comment #7
coltraneThanks @jerebe, good catch.
Comment #9
coltraneFixed
Comment #11
kristofferwiklund commentedCould we have a new release of the module, because of this. It breaks login completely.