Hi,
I am developing a new project in PHP.
For that i want to generate the random password for each users. but i don't know how to do this.
please help.
Hi,
I am developing a new project in PHP.
For that i want to generate the random password for each users. but i don't know how to do this.
please help.
If you want to generate the random password using the string you can use the rand function
It’s easy to use to use the rand(min, max) function to generate a random number between min and max (inclusive).
Here is a clever way of using rand() and chr() function to generate a random string:
chr(rand(65,90)) will generate a random character between A - Z (capital)
chr(rand(97,122)) will generate a random character between a - z (lower case)
Therefore, if you want to generate a 5 character long string of random string (assuming all lower case), you would write:
$RandomString=chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,122)).chr(rand(97,12 2));
Or you can write a simple for() loop and concatenate them together.
Hope that helps.
To Generates a random string of variable length you can use this given function.
Code:function getUniqueCode($length = "") { $code = md5(uniqid(rand(), true)); if ($length != "") return substr($code, 0, $length); else return $code; }
Bookmarks