PHPBuilder - QUICK random string generator



RSS Twitter
Snippets Algorithms

QUICK random string generator

by: Paul Appleyard
|
July 10, 2002

Version: 1.0

Type: Function

Category: Algorithms

License: GNU General Public License

Description: function that returns password of length n containing alphanumeric characters (A-z, a-z, 0-9)



function getPass($length=8)
{
$code = "";
$arr = array();

// Generate 62 element array with all posiible chars
$arr = array_merge(range(0,9),range('a','z'),range('A','Z'));

// srand not needed for php 4.2.0 and up
srand ((float) microtime() * 10000000);

foreach (range(1,$length) as $tmp) {
    $code .= $arr[rand(0,61)];
}
return $pass;
}

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Paul Appleyard

Comment:



Comment:

(Maximum characters: 1200). You have characters left.