PHPBuilder - The Smartest way to generate random passwords



RSS Twitter
Snippets Algorithms

The Smartest way to generate random passwords

by: Walid Karray
|
October 7, 2009

Version: 1

Type: Function

Category: Algorithms

License: GNU General Public License

Description: Generate random password from a set of chars ($pool)



	/*
	 * Generate random password from a set of chars ($pool)
	 * 
	 * @param	integer	$len	Password length
	 * @return	string	Rand password
	 */
	private function generateRandomPasswd($len = 10) {
		$string = '';
		$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
		for($i = 1; $i <= $len; $i ++) {
			$string .= substr ( $pool, rand ( 0, 61 ), 1 );
		}
		
		return $string;
	}

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Walid Karray

Comment:



Comment:

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