/**
* 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 = '';
{
$lowercaseCharacters = 'abcdefghijklmnopqrstuvwxyz';
$uppercaseCharacters = strtoupper($lowercaseCharacters); $numericCharacters = '0123456789';
$specialCharacters = '!@#$%^&';
$availableCharacters = ($lowercase ? $lowercaseCharacters : '')
. ($uppercase ? $uppercaseCharacters : '')
. ($numeric ? $numericCharacters : '')
. ($special ? $specialCharacters : '');
}
for ($i = 0; $i < $length; $i++)
{
$generatedPassword .= substr($availableCharacters, rand(0, strlen($availableCharacters) - 1), 1); }
return $generatedPassword;
}