Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-01-2009
Member
 
Join Date: Dec 2008
Posts: 35
Generate Random Password In PHP

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.
Reply With Quote
  #2  
Old 23-01-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Rand function In PHP

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.
Reply With Quote
  #3  
Old 23-01-2009
Member
 
Join Date: May 2008
Posts: 2,293
Generate random string of variable length

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;
      }
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Generate Random Password In PHP"
Thread Thread Starter Forum Replies Last Post
Generate some quality of random number via Random Number Generation function aMADeO! Windows Software 4 13-01-2012 05:07 PM
How to use "Math.random()" to generate a random number in JavaScript? Silent~Kid Software Development 5 03-02-2010 05:06 AM
Generate random number using VB Bambina Software Development 2 02-09-2009 10:56 PM
Generate random data in excel garfield1 Software Development 3 12-08-2009 10:40 AM
How to Generate Random Password in vb.net Aaprichit Software Development 1 24-12-2008 07:05 PM


All times are GMT +5.5. The time now is 11:08 AM.