PHPBuilder - Customizable Random Password Generator



RSS Twitter
Snippets Algorithms

Customizable Random Password Generator

by: Blake Caldwell
|
June 5, 2001

Version: 2.0

Type: Function

Category: Algorithms

License: GNU General Public License

Description: Random password generator that you can customize to include uppcase letters, lowercase letters, and numbers, as well as the length of the password. Read the comments for more info.




# return a randomly-generated string with input length
# Blake Caldwell <blake@pluginbox.com>
function randomString($length=15){
	static $srand;
	if($srand != true){
		$srand = true;
		srand((double)microtime()*1000000);		# only seed once!
	}
	$chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for($i=0; $i<$length; $i++){
		$result .= substr($chars,rand(0,strlen($chars)-1),1);
	}
	return $result;
}

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Blake Caldwell

Comment:



Comment:

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