PHP : simple password generator

This is a discussion on PHP : simple password generator within the Tutorials & Stuff! forums, part of the KP's Network Forum category; In this tutorial we will be learning how to create a random password using nothing but loops and random letters. ...

Try Our customized MMoRPG experience, using World of Warcraft Client to connect
  

Reply

 

LinkBack Thread Tools
Old October 10th, 2004   #1 (permalink)
KingPin
Da Boss!
Starship Legend Champion
 
KingPin's Avatar
 
Join Date: Apr 2004
Location: Brooklyn, NY
Posts: 7,539
Thanks: 53
Thanked 72 Times in 50 Posts
Blog Entries: 24
My Mood: Lurking
KingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.O
KingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.OKingPin KingPin o.O
PHP : simple password generator

In this tutorial we will be learning how to create a random password using nothing but loops and random letters. For extra security we will define a minimum length and a maximum length, we will also make it so a password can't be defined from using the url.


First we need to define everything. This includes the min length, max length and emptying the password:

$min=4;
$max=15;
$pwd="";

Now we need to start the loop of creating it, using the $min and $max we can get a random length:

for($i=0;$i
We need to get a load of letters now, but we have to be sure there are valid letters and not other characters:

$num=rand(48,122);
if(($num > 97 && $num [ 122))
{
$pwd.=chr($num);
}

else if(($num ] 65 && $num [ 90))
{
$pwd.=chr($num);
}

else if(($num ]48 && $num < 57))
{
$pwd.=chr($num);
}

else if($num==95)
{
$pwd.=chr($num);
}

Just a load of checking, nothing much really there. Because this is a tutorial, we would output the result of our password:

echo $pwd;

Be carefull about including that line for the final script. If you are emailing the password then you don't need it, you decide.

The complete code is here:

// filename "pword.php"


$min=4; // minimum length of password
$max=15; // maximum length of password
$pwd=""; // to store generated password

for($i=0;$i {
$num=rand(48,122);

if(($num > 97 && $num [ 122))
{
$pwd.=chr($num);
}

else if(($num ] 65 && $num [ 90))
{
$pwd.=chr($num);
}

else if(($num ]48 && $num [ 57))
{
$pwd.=chr($num);
}

else if($num==95)
{
$pwd.=chr($num);
}

else
{
$i--;
}
}

echo $pwd; // prints the password
?]

Heaven doesn't want me, and hell is afraid I'll take over.NO SUPPORT VIA PM.

KingPin is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 25th, 2005   #2 (permalink)
.:XFX:. Member
 
blackops's Avatar
 
Join Date: Jan 2005
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
blackops is an unknown quantity at this point
PHP : simple password generator

DONE
blackops is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
php, simple, password, generator


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:02.

no new posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89