Jul 30,  PST

Random Password Generator PHP Script
Written by: Haily, Icy | Easily create a script that can generate a random string of text that may be used as a password or anything else.
 Facebook Google Buzz Mxx Digg StumbleUpon  

This article will show you how to create a random password generator script. Please read on, and comment below if you have
any questions at all.

The setup for this is fairly simple. The function that generates the password goes through the $characters variable and selects a random character to generate the password until the length of the desired password:

Code:
<?php

function randomPassword ($length = 7){

// define possible characters
$characters = "abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*";

// using the for loop to add random characters to $password until $length is reached
for ($y=1; $y<=$length; $y++){

//randomly selecting characters and building the password with them
$randompw = rand() %strlen($characters);
$temp = substr($characters, $randompw,1);
$password = $password . $temp;

}

return $password;

}

echo "Generated Password: " .randomPassword();

?>

You can use this function to easily generate random passwords. Instead of calling up the function simply as randomPassword() to call up a 7-character long password, you can insert a number as a parameter to generate a password of any length. For example, randomPassword(5) or randomPassword(10) for various password lengths. Try it out for yourself. Enjoy!

 Facebook Google Buzz Mxx Digg StumbleUpon  

| Written by: Haily, Icy | Added: Feb 11 2010 | Last Modified: Feb 11 2010 | Views: 979 | (Log in to rate) |

Member Comments

jules of rabidish.orgFebruary 12 2010, 2:48 am PST - Karma: 0 - Quote - Link -
5/5
Great article Haily & Icy! I've always wanted to know how to make this, never knew how easy it was. Not to mention it is customisable too. It is so simple!
Grace of moonwalked.netFebruary 12 2010, 3:12 am PST - Karma: 0 - Quote - Link -
5/5
Just tried it, works great I love random passwords.  
Puffs of ipawd.netFebruary 12 2010, 3:23 pm PST - Karma: 0 - Quote - Link -
5/5
That's so cool!

You are not currently logged into your IceCaves account. Log in?

Username: Password: | Create an account 

If you would prefer, you can post as a guest below:

Name:
Email: (required; for identification purposes; will not be published)
Site URL: (optional)
Rate:You must log in in order to rate.
Post:
BBCode?

Smilies:
Human Check:

Username:

Password:


FigmintAmour Chaleur

The IceCaves.net Topsites


Neo Crave | Enchant Me Not | FGN-Guild.com | Rabidish | Unloadeed | Blue Stapler | Moonwalked.net | RockyRoadRules | KeliJo.net | Daily Neopets | RainbowBliss | Tugboat | Guildpets | NeoWishes | Neo Nutters | Neoeditor | Gamexe.net | Dash of Color | Figmint | Hearted Kind | Skyline Designs | Darkgirl's Life | Neo-Richies | Geeks' Planet