₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,212 members, 8,420,833 topics. Date: Friday, 05 June 2026 at 12:12 PM

Toggle theme

Please I Need A Code To Generate Random Password In Php - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease I Need A Code To Generate Random Password In Php (870 Views)

1 Reply (Go Down)

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
1 Reply

I Need A Code From You HelpVb.net Code To Display Image In Picturebox From Sql ServerI Need A Code To Allow Download From234

Gui Development Java C++Am New To JavaCreating An Event Notifier With Vb.net