Archive for the 'PHP' Category

A random Password Generator script - Full featured

Here is random Password generator function, it can produce complex passwords of any desired length. It can generate passwords which are alpha-numeric + with special characters (optional) + upper and lower case mixed within it.

 function generateCode($characters,$special_char=false) {
        $possible = '1234567890abcdefghijklmnopqrstuvwxyz';
            if($special_char)
              $possible .= '!@#$%^&*()_+-=[]{};\':",./\\<>?|`~';
        $code = '';
        $i = 0;
        while ($i < $characters) {
         $code1 = substr($possible, mt_rand(0, strlen($possible)-1), 1);
         if(rand()%2==0)
         $code1= strtoupper($code1);
         $code .=$code1;
         $i++;
         }

        return $code;
 }
 

Features of this function:

  • Alpha-numeric passwords
  • You can get random password of any desired length
  • Can produce password of combined upper and lowercase characters.
  • Can optionally produce passwords with special characters

Suppose you want to produce password of length 8 characters, then the syntax to call the function is

generateCode(8);
 

If you want to create password with special characters also, then the syntax will be

generateCode(8,true);
 

Some examples of generated passwords are:
Mm69lIGf
“)5E%\{7
M4p3OVEod6Dq9cJZMkGZMEnm31JVGcNY8iK
J4j:8~-72)^fF>=6)S<(”{~->a0gQ6(DrEk



If you don’t need a complex passwords generator like this then you can try A simple Password Generator here it is one-line code which can generate simple random passwords.

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,

       substr(md5(rand()),0,8);
 

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:
861cf
3ed0d10f
33dc56970486a86b15cc



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.

What is PHP?

PHP - HyperText PreProcessor. It is a Open Source, server-side scripting language. Today PHP is one of the most popular and advanced languages. It was first designed by Rasmus Lerdorf in the year 1995, since then it has gained wide popularity and has attained a high position the world of programming by the contribution of it’s huge open source community.

PHP is used mainly in server-side scripting and Web Applications, but can be used from a command line interface or in standalone graphical applications. Unlike an ordinary HTML page, a PHP script is not sent directly to a client by the server; instead, it is parsed by the PHP binary or module, which is server-side installed. PHP code in a script can query databases, create images, read and write files, talk to remote servers - the possibilities are endless.

The output from PHP code is combined with the HTML in the script and the result sent to the user’s web-browser, therefore it can never tell the user whether the web-server uses PHP or not, because all the browser sees is HTML.

PHP’s support for Apache and MySQL further increases its popularity. Apache is now the most-used web-server in the world, and PHP can be compiled as an Apache module. MySQL is a powerful free SQL database, and PHP provides a comprehensive set of functions for working with it. The combination of Apache, MySQL and PHP is all but unbeatable.