Monday, January 4, 2010

How to create simple password generator using PHP

How to create simple password generator using PHP
Hi coding freak. It's been a long time no see. Previous authors apologize in advance for late availability of new articles about PHP tutorial. Mainly due to my busy in the real world that need special attention. Please understandable. I am also human, have a sense and have a heart ... : D

The reason why I raise this topic to become the title is, sometimes multiple users and web administrators have a trouble to create
a good password, and most of them are also looking for a password that will expect their password away from bad activities like cracking passwords with brute-force method or matching password dictionary method. Thing that I will explain here is how to create secure passwords, though as I have said before "There is no 100% safe in cyberspace." Everything has a risk of course. And to implement it all depends on your creativity in using the password generator. Now let's begin this PHP tutorial :D

The full script as follows:

 // password.gen.php


function make_password($num_chars) {
    if ((is_numeric($num_chars)) && ($num_chars >= 6) && (! is_null($num_chars))) {

        $password = "";
        $accepted_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWYZ1234567890~!@#$%^&*+|}{:>?<";

        srand(((int)((double)microtime()*1000003)) );

        for ($i=1; $i<=$num_chars; $i++) {
            $random_number = rand(0, (strlen($accepted_chars) -1));
            $password .= $accepted_chars[$random_number] ;

        return $password;
    echo "Password must be more than 6 letters";


<html><head><title>Password Generator</title></head>
Your password : <br><font style='BACKGROUND-COLOR:yellow'><b>
<?php echo make_password($_POST['size']); ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="size" value="<?php echo $_POST['size']; ?>" >
<input type="submit" name="submit" value="Create!!">

Now i will try to explain some of the script above

if ((is_numeric ($ num_chars)) & & ($ num_chars> = 6) & & (! is_null ($ num_chars))) (
If the input entered by the user is a number / numbers and numerical characters number more than 6 digits then...

$ password = "";

$ accepted_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WYZ1234567890 ~!@#$%^&*+|}{:>?<";
Prepare characters, numbers and special characters that will be used as a password.

srand (((int) ((double) microtime () * 1000003)));
Then do the randomization possibilities of characters, numbers, or special characters that later on took a part of the password.

for ($ i = 1; $ i <= $ num_chars; $ i + +)
Perform as many repetitions depending from the input numbers...

$ random_number = rand (0, (strlen ($ accepted_chars) -1))
Create a randomized selection of characters, numbers, special characters, from a collection of characters that had been prepared earlier ...

$ password .= $ accepted_chars [$ random_number];
Enter the characters one by one taken into variable $ password


That's all about this PHP tutorial...quite easy right? you should try it :D

If there is a question, just feel free to ask

You can download this tutorial here

Related Posts by Categories


Anonymous said...

Thanks for this useful tutorial

Post a Comment

Maybe this is what you looking for


Subscribe Now


IT Skill is not enough... Copyright © 2009 Designed by Bie Blogger Template