Please I Need A Code To Generate Random Password In Php - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Please I Need A Code To Generate Random Password In Php (870 Views)
| Please I Need A Code To Generate Random Password In Php by ebenz1(op): 11:53am On Jun 25, 2009 |
Please let somebody show me a code to generate random password when a page is visited. i need to give a password to subscribers after been redirected back from a payment processor in which they will be able to login with it. |
| Re: Please I Need A Code To Generate Random Password In Php by lojik(m): 7:51pm On Jun 25, 2009 |
//create a function to choose a single character at random from a defined set of characters function getRandomChar() { $charSet = "123456789abcdefghijklmnpqrstuvwxyz"; //The character set u wanna build passwords from $rn = rand (0, strlen ($charSet)); //Choose a random position in character set return substr ($charSet, $rn, 1); //Return the character at that position } //create function to choose a given length password by using getRandomChar() function getPassword($length) { $pass = ""; //make pass an empty string //loop for no of time specified by length of password for ($idx = 0; $idx < $length; $idx++) { $pass .= getRandomChar(); //add a random character to pass } return $pass; } //Usage example $nuPassword = getPassword(6); //returns a password that is 6 characters long |
| Re: Please I Need A Code To Generate Random Password In Php by lojik(m): 8:00pm On Jun 25, 2009 |
Now this is the code without the comments function getRandomChar() { $charSet = "123456789abcdefghijklmnpqrstuvwxyz"; $rn = rand (0, strlen ($charSet)); return substr ($charSet, $rn, 1); } function getPassword($length) { $pass = ""; for ($idx = 0; $idx < $length; $idx++) { $pass .= getRandomChar(); } return $pass; } |
| Re: Please I Need A Code To Generate Random Password In Php by ebenz1(op): 11:13am On Jun 27, 2009 |
Thanks Logic. I'll try it out and hope it suits my use. thanks once again |
I Need A Code From You Help • Vb.net Code To Display Image In Picturebox From Sql Server • I Need A Code To Allow Download From • 2 • 3 • 4
Gui Development Java C++ • Am New To Java • Creating An Event Notifier With Vb.net