Skip to content

Commit

Permalink
Changing token generator function. Reason: compatibility with some ph…
Browse files Browse the repository at this point in the history
…p versions
  • Loading branch information
hugodias committed Jan 12, 2015
1 parent 7c773dd commit a53b43c
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions Controller/Component/UtilComponent.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php

class UtilComponent extends Component
{

public function crypto_rand_secure($min, $max)
public function crypto_rand_secure()
{
$range = $max - $min;
if ($range < 0) {
return $min;
} // not so random...
$log = log($range, 2);
$bytes = (int)($log / 8) + 1; // length in bytes
$bits = (int)$log + 1; // length in bits
$filter = (int)(1 << $bits) - 1; // set all lower bits to 1
do {
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
$rnd = $rnd & $filter; // discard irrelevant bits
} while ($rnd >= $range);
return $min + $rnd;
return md5(uniqid(mt_rand(), true));
}

public function getToken($length = 32)
Expand All @@ -25,7 +14,7 @@ public function getToken($length = 32)
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$codeAlphabet .= "abcdefghijklmnopqrstuvwxyz";
$codeAlphabet .= "0123456789";
for ($i = 0 ; $i < $length ; $i++) {
for ($i = 0; $i < $length; $i++) {
$token .= $codeAlphabet[$this->crypto_rand_secure(0, strlen($codeAlphabet))];
}
return $token;
Expand Down

1 comment on commit a53b43c

@vahidqara
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good.. i am The problem show gallery in Firefox?!?!?!?!?

Please sign in to comment.