This release is a PHP function. It requires multiple parameters, and returns a string. Based on the parameters entered, the string returned will be a possible option for a random password for you or anyone of your users to use.
He has documentation at the start of the function to tell you which each parameter is.
PHP Code:
function GeneratePassword( $l, $s, $n, $uc, $lc )
{
/** ABOUT THE PARAMETERS
* $l - integer - length of the password to be generated
* $s - integer - include symbols in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
* $n - integer - include numbers in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
* $uc - integer - include upper-case characters in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
* $lc - integer - include lower-case characters in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
*/
In terms of the code itself, it is alright. Right off the bat, I suggest that you use booleans instead of integers that only handle 0/1 (for the parameters).
From the looks of the code, this line:
PHP Code:
if ( !$s || !$n || !$uc || !$lc ) $characters_to_include = $numbers . $upper . $lower;
will not act as wanted. The comments claim that the if will only be true if nothing is selected, i.e. the last 4 parameters are all 0[false]. The problem is that this will return true if even one of them is set to 0[false]. Change each
|| to
&& to fix this.
There are one or two things you could simplify about the code, but it may hinder on customizability or/and novice end-developers(i.e. people using this code in their scripts) understanding of the function.
For example, you could remove the $upper variable and instead use
PHP Code:
if ( $uc == "1" ) $characters_to_include .= strtoupper($lower);
I like how it returns a string after it has been 'secured' via the htmlentities function; this is very good, especially since it may be displayed to the end user.
For added customizability, you
could make the configuration variables - currently hardcoded in to the functions - take their data from globals (ex. $GLOBAL['lower']). This would allow the end-developer to easily change a certain configuration variable for this function in the midst of doing pretty much anything else.
But, since this is a relatively simplistic function, and one that most people won't need to change the configuration variables, let alone in the midst of doing something else in the code.. this probably would add more hassle than anything.
My last minor suggestion would be to use english-esque variable names for something with this many parameters. You do this for the most part throughout the function - except for the parameters. If someone forgets what the parameters mean, then they would have to reread the documentation within the function. If you used english-esque variable names, ex.
$includeUpper instead of
$uc, then most people would be able to look at the parameter names and immediately know exactly what they are used for.