Create Random Alphanumeric Password in PHP

We can use this simple password generation function to create random passwords. The maximum limit of generated password is 36 characters.

<?php
	function gen_password($size = 8) {
		$size = $size > 36 ? 30 : $size;
		$pool = array_merge(range(0, 9), range('A', 'Z'));
		$rand_keys = array_rand($pool, $size);
 
		$password = '';
 
		foreach ($rand_keys as $key) {
			$password .= $pool[$key];
		}
 
		return $password;
	}
 
	$password = gen_password(10);
?>

We can use it like this.

<?php
	$password = gen_password(10);
?>

,


  1. No comments yet.
(will not be published)

 


Submit Comment
Subscribe to comments feed