Bugfix in generate random string.
authorphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 11 Feb 2002 19:36:12 +0000 (19:36 +0000)
committerphilippe_mingo <philippe_mingo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 11 Feb 2002 19:36:12 +0000 (19:36 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2419 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/strings.php

index 722cedeca8bae5ddf2dac4cf28ee1cb3db17b2d4..e9bac3f31b7cf5a15e41f10bc2627bfdb638060f 100644 (file)
@@ -539,14 +539,15 @@ function GenerateRandomString($size, $chars, $flags = 0) {
     if (($size < 1) || (strlen($chars) < 1)) {
         return '';
     }
-    
+
     sq_mt_randomize(); /* Initialize the random number generator */
-    
+
     $String = '';
+    $j = strlen( $chars ) - 1;
     while (strlen($String) < $size) {
-        $String .= $chars[mt_rand(0, strlen($chars))];
+        $String .= $chars{mt_rand(0, $j)};
     }
-    
+
     return $String;
 }