summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-04-09 13:46:31 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-04-09 20:48:17 +0200
commit5940316125c1672b72eb08186e6c43f5a91e71ef (patch)
tree1faaaa87d116a64d60fdbcf513139bd05c3ea4e6
parentc0f1755842211996a7a21ffb8773b260bb2be281 (diff)
random_id() -> random_alphanum(); allow single argument
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--application/controllers/user.php2
-rw-r--r--application/helpers/filebin_helper.php10
-rw-r--r--application/models/file_mod.php2
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();