Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,464 members, 7,816,086 topics. Date: Friday, 03 May 2024 at 03:39 AM

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 (812 Views)

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)

(1) (Reply) (Go Down)

Please I Need A Code To Generate Random Password In Php by ebenz1(m): 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(m): 11:13am On Jun 27, 2009
Thanks Logic.
I'll try it out and hope it suits my use.
thanks once again

(1) (Reply)

Please Help Me On This And God Will Help You Too / Help On Php / Password Encryption

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.