$wordsPickedFinal = addCharacter($wordsPickedAndNumber); $passwordString = printPassword($wordsPickedFinal, $passwordString); } else { if ($includeNumber) { generatePassword($numberOfWords, $wordList); $wordsPicked = addNumber($wordsPicked); $passwordString = printPassword($wordsPicked, $passwordString); } else { if ($specialCharacter) { generatePassword($numberOfWords, $wordList); $wordsPicked = addCharacter($wordsPicked); $passwordString = printPassword($wordsPicked, $passwordString); } else { //$wordsPicked = generatePassword($numberOfWords, $wordsPicked, $wordList); generatePassword($numberOfWords, $wordList); $passwordString = printPassword($wordsPicked, $passwordString); } } } } /* * This is a function that generates random words inside an array. * @param: $numberOfWords, $array, $wordList * @return: N/A */ function generatePassword($numberOfWords, $wordList) { global $wordsPicked; // pick random numbers that matches the number user inputs for ($i = 0; $i < $numberOfWords; $i++) { $randomNumber = rand(0, count($wordList) - 1);
if (isset($_POST["numberOfWords"])) { $numberOfWords = $_POST["numberOfWords"]; if ($numberOfWords <= 0 or $numberOfWords > 4) { $errorMessage = "Please enter a valid number of words!"; } else { $numberOfWords = $_POST["numberOfWords"]; } } # now we need a new array for the selected words $wordsSelected = array(); # make sure that the $numberOfWords is valid. If not, return with the error message if ($numberOfWords <= 0 or $numberOfWords > 4) { return; } else { $wordsSelected = generatePassword($numberOfWords, $wordsSelected, $listOfWords); $passwordUnique = printPassword($wordsSelected, $passwordUnique); } function generatePassword($numberOfWords, $array, $listOfWords) { # then we want the words picked randomly for ($i = 0; $i < $numberOfWords; $i++) { $randomNumber = rand(0, count($listOfWords) - 1); #finish her up array_push($array, $listOfWords[$randomNumber]); } return $array; } function printPassword($wordsSelected, $passwordUnique) { for ($i = 0; $i < count($wordsSelected); $i++) { $passwordUnique .= $wordsSelected[$i] . "";