aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorGraham Eames <grahamje@users.sourceforge.net>2006-04-21 20:42:10 +0000
committerGraham Eames <grahamje@users.sourceforge.net>2006-04-21 20:42:10 +0000
commit6f4c1b1a22fc280fdc8a202c977eac1c5acee37a (patch)
tree176c87abd9fd54ed7ea9b13eaf8e119ee0a77586 /phpBB/includes/functions.php
parent10e8b6130da5babaf0f44535d8def064af544cd2 (diff)
downloadforums-6f4c1b1a22fc280fdc8a202c977eac1c5acee37a.tar
forums-6f4c1b1a22fc280fdc8a202c977eac1c5acee37a.tar.gz
forums-6f4c1b1a22fc280fdc8a202c977eac1c5acee37a.tar.bz2
forums-6f4c1b1a22fc280fdc8a202c977eac1c5acee37a.tar.xz
forums-6f4c1b1a22fc280fdc8a202c977eac1c5acee37a.zip
Porting the random number generator code over
Fingers crossed that this doesn't break anything.... ;-) git-svn-id: file:///svn/phpbb/trunk@5813 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php35
1 files changed, 19 insertions, 16 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 5ca15e493d..8936f381c0 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -122,29 +122,32 @@ function set_config($config_name, $config_value, $is_dynamic = false)
/**
* Generates an alphanumeric random string of given length
*/
-function gen_rand_string($num_chars)
+function gen_rand_string($num_chars = 8)
{
- $chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9');
+ $rand_str = dss_rand();
- $max_chars = sizeof($chars) - 1;
- $rand_str = '';
- for ($i = 0; $i < $num_chars; $i++)
- {
- $rand_str .= $chars[mt_rand(0, $max_chars)];
- }
-
- return $rand_str;
+ return substr($rand_str, 0, $num_chars);
}
/**
* Return unique id
-* @param $extra additional entropy for call to mt_srand
+* @param $extra additional entropy
*/
-function unique_id($extra = 0, $prefix = false)
+function unique_id($extra = 'c')
{
- list($usec, $sec) = explode(' ', microtime());
- mt_srand((float) $extra + (float) $sec + ((float) $usec * 100000));
- return uniqid(($prefix === false) ? mt_rand() : $prefix, true);
+ global $db, $config, $dss_seeded;
+
+ $val = $config['rand_seed'] . microtime();
+ $val = md5($val);
+ $config['rand_seed'] = md5($config['rand_seed'] . $val . $extra);
+
+ if($dss_seeded !== true)
+ {
+ set_config('rand_seed', $config['rand_seed']);
+ $dss_seeded = true;
+ }
+
+ return substr($val, 4, 16);
}
/**
@@ -1448,7 +1451,7 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa
// Generate code
$code = gen_rand_string(mt_rand(5, 8));
- $confirm_id = md5(unique_id(0, $user->ip));
+ $confirm_id = md5(unique_id($user->ip));
$sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
'confirm_id' => (string) $confirm_id,