Results 1 to 3 of 3

Thread: Generate Random Password In PHP

  1. #1
    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    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;
          }

Similar Threads

  1. Replies: 4
    Last Post: 13-01-2012, 05:07 PM
  2. How to use "Math.random()" to generate a random number in JavaScript?
    By Silent~Kid in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 05:06 AM
  3. Generate random number using VB
    By Bambina in forum Software Development
    Replies: 2
    Last Post: 02-09-2009, 10:56 PM
  4. Generate random data in excel
    By garfield1 in forum Software Development
    Replies: 3
    Last Post: 12-08-2009, 10:40 AM
  5. How to Generate Random Password in vb.net
    By Aaprichit in forum Software Development
    Replies: 1
    Last Post: 24-12-2008, 07:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,618,245.26887 seconds with 16 queries