arathi Posted October 17, 2007 Share Posted October 17, 2007 Hi, I want to create random password. How can I create random passwords? Link to comment https://forums.phpfreaks.com/topic/73642-create-random-password/ Share on other sites More sharing options...
steve448 Posted October 17, 2007 Share Posted October 17, 2007 Hi, I have a function that I always use for passwords: function generatePassword ($length = { // start with a blank password $Password = ""; // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyz"; // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < $length) { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($Password, $char)) { $Password .= $char; $i++; } } // done! return $Password; } You can then create a password by: $password = generatePassword(); Hope this helps Link to comment https://forums.phpfreaks.com/topic/73642-create-random-password/#findComment-371509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.