diff options
-rw-r--r-- | application/controllers/user.php | 2 | ||||
-rw-r--r-- | application/helpers/filebin_helper.php | 10 | ||||
-rw-r--r-- | application/models/file_mod.php | 2 |
3 files changed, 9 insertions, 5 deletions
diff --git a/application/controllers/user.php b/application/controllers/user.php index 4fffbef9b..5795db158 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -77,7 +77,7 @@ class User extends CI_Controller { return; } - $key = random_id(12, 16); + $key = random_alphanum(12, 16); $this->db->query(" INSERT INTO invitations diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 3dcd03794..ac09da7d2 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -182,17 +182,21 @@ function is_cli_client() return false; } -function random_id($min_length, $max_length) +function random_alphanum($min_length, $max_length = null) { $random = ''; $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char_list .= "abcdefghijklmnopqrstuvwxyz"; $char_list .= "1234567890"; - $length = rand()%($max_length-$min_length) + $min_length; + + if ($max_length === null) { + $max_length = $min_length; + } + $length = mt_rand($min_length, $max_length); for($i = 0; $i < $max_length; $i++) { if (strlen($random) == $length) break; - $random .= substr($char_list,(rand()%(strlen($char_list))), 1); + $random .= substr($char_list, mt_rand(0, strlen($char_list)), 1); } return $random; } diff --git a/application/models/file_mod.php b/application/models/file_mod.php index 1f1fa5f49..b6194a39e 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -23,7 +23,7 @@ class File_mod extends CI_Model { // TODO: make threadsafe function new_id() { - $id = random_id(3,6); + $id = random_alphanum(3,6); if ($this->id_exists($id) || $id == 'file' || $id == 'user') { return $this->new_id(); |