A simple Password Generator

There are many big and complex Password generator scripts available on the Internet, but often we don’t need to go into such complexities.

Here is a simple one-line password generator code in PHP,


First, a random number is taken, then the MD5 hashing is done on it, then a substring is taken from that. That substring is your generated password.

In the above code just change the the last number (which is ‘8′ here), to get your desired length of password.

However this has two small limitations:

  • Though the generated password will be alpha-numeric, the characters will not go beyond ‘F’ , since they are hex codes.
  • Password length cannot be more than 32 characters, since a MD5 hash is taken. However you can always concatenate this code one after another to get any desired length of random password.

Anyway, these are very simple limitations, this will not bother you in ordinary cases.

Some examples of generated password are:

If you need a password generator without these limitations then you can try A Full featured Password Generator here, this complex password generator can produce alpha-numeric passwords of any length.

Last Modified: February 28, 2008 @ 21:03

This entry was posted on Thursday, February 28th, 2008 at 6:51 PM and is filed under PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “A simple Password Generator”

  1. dernier bar à oxygène avec Said on

    It’s actually a great and useful piece of information. I’m glad that you shared this useful info with us. Please keep us up to date like this. Thanks for sharing.

  2. oxybar pourri Said on


  3. Verla Policicchio Said on

    Thanks for taking the time to discuss this, I feel strongly about it and love learning extra on this topic. If doable, as you acquire experience, would you mind updating your blog with further information? This can be very useful for me.

Leave a Reply

You must be logged in to post a comment.