• home
  • forum
  • my
  • kt
  • download
  • Creating a Random Password Generator

    Author: 2008-08-18 09:41:09 From:

    In this PHP tutorial, I'll show you how to create a script that randomly generates a unique id based on the current time, it's perfect for unique password generation.

    Create a page named random_id.php
    Add the following:
    CODE
    <?php
    //set the random id length
    $random_id_length = 10;

    //generate a random id encrypt it and store it in $rnd_id
    $rnd_id = crypt(uniqid(rand(),1));

    //to remove any slashes that might have come
    $rnd_id = strip_tags(stripslashes($rnd_id));

    //Removing any . or / and reversing the string
    $rnd_id = str_replace(".","",$rnd_id);
    $rnd_id = strrev(str_replace("/","",$rnd_id));

    //finally I take the first 10 characters from the $rnd_id
    $rnd_id = substr($rnd_id,0,$random_id_length);

    echo "Random Id: $rnd_id";
    ?>


    Basically what uniqid does is, it generates a UNIQUE id based on the current time in microseconds and then we use the crypt function to do a one way encryption of the same.
    This creates the random password, uniquely.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (6)
      Mailing List Management (8)
      Miscellaneous (10)
      Networking (6)
      News Publishing (6)
      OOP (8)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (5)
      Postcards (0)
      Randomizing (11)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot