Alleen de functie:

    /**
     * This function creates a random password. It accepts several parameters for maximum flexibility. It is
     * possible to set the length of the password which will be returned. The developer can also choose which
     * kind of characters he/she would like to allow. If the sixth parameter is supplied with a string, those
     * characters will be used for the generation of the password. If all parameters are set to false the
     * returned password will use only lowercase characters.
     * 
     * @version 1.0
     * @author Nick Smit <nick.smit@quicknet.nl>
     * @author Gerard Klomp <gerard.klomp@sitemasters.be>
     * @license MIT License - http://www.sitemasters.be/mit-license.txt
     * @param integer $length[optional] The length of the password
     * @param boolean $lowercase[optional] Should the function use lowercase characters, default value is true
     * @param boolean $uppercase[optional] Should the function use uppercase characters, default value is true
     * @param boolean $numeric[optional] Should the function use numeric characters, default value is true
     * @param boolean $special[optional] Should the function use special symbols, default value is false
     * @param string $availableCharacters[optional] This parameter accepts a string with characters which are used for generation of the password
     * @return string The randomly created password
     */
    function createPassword($length = 8, $lowercase = true, $uppercase = true, $numeric = true, $special = false, $availableCharacters = null)
    {
        $generatedPassword = '';
        
        if (is_null($availableCharacters))
        {
            $lowercaseCharacters = 'abcdefghijklmnopqrstuvwxyz';
            $uppercaseCharacters = strtoupper($lowercaseCharacters);
            $numericCharacters   = '0123456789';
            $specialCharacters   = '!@#$%^&';
            
            $availableCharacters = ($lowercase ? $lowercaseCharacters : '')
                                 . ($uppercase ? $uppercaseCharacters : '')
                                 . ($numeric   ? $numericCharacters   : '')
                                 . ($special   ? $specialCharacters   : '');
                                 
            $availableCharacters = strlen($availableCharacters) == 0 ? str_shuffle($lowercase) : str_shuffle($availableCharacters);
        }
        
        for ($i = 0; $i < $length; $i++)
        {
            $generatedPassword .= substr($availableCharacters, rand(0, strlen($availableCharacters) - 1), 1);
        }
        
        return $generatedPassword;
    }

Voorbeeld voor gebruik:
[code=PHP]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Password Generator Voorbeeld</title>
</head>

<body>
<?PHP
include "generatePassword.php";
echo generatePassword('12');
?>
</body>
</html>
