Skip to content

Commit

Permalink
Merge pull request phalcon#11667 from sergeyklay/2.1.x
Browse files Browse the repository at this point in the history
Improved Random::number
  • Loading branch information
sergeyklay committed Apr 14, 2016
2 parents c0cdc8a + e725ade commit 45ffece
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"optimizer-dirs": [
"optimizers"
],
"prototype-dir": {
"php7": "prototypes/php7"
},
"constants-sources": [
"ext/phalcon/mvc/model/query/scanner.h",
"ext/phalcon/annotations/scanner.h",
Expand Down
7 changes: 6 additions & 1 deletion phalcon/security/random.zep
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,13 @@ class Random
throw new Exception("Require a positive integer > 0");
}

if function_exists("random_int") {
return random_int(0, len);
}

if function_exists("\\Sodium\\randombytes_uniform") {
return \\Sodium\\randombytes_uniform(len);
// \Sodium\randombytes_uniform will return a random integer between 0 and len - 1
return \\Sodium\\randombytes_uniform(len) + 1;
}

let hex = dechex(len);
Expand Down
12 changes: 12 additions & 0 deletions prototypes/php7/php7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* PHP 7 prototypes
*/

if (!function_exists('random_bytes')) {
function random_bytes($length) {}
}

if (!function_exists('random_int')) {
function random_int($min, $max) {}
}

0 comments on commit 45ffece

Please sign in to comment.