Random password generator with PHP

function generate_password($length='')
for($i=0; $i<$length; $i++){$password.=$str{rand(0,$max-1)};}
return $password;

In the above code the PHP function generate_password() takes one optional argument, the length of the password. If you do not specify the length then this function will return a random password of length from eight to twelve characters. PHP variavle $str hold the characters to be used to generate password. You can edit this string according to your need.


One thought on “Random password generator with PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s