case 3: $passwordArray[$i] = getVerb(); break; case 4: $passwordArray[$i] = getAdverb(); break; } } return $passwordArray; } function randSym() { $symArray = ['!', '@', '#', '$', '%', '^', '&', '*']; return $symArray[rand(0, 7)]; } $newPassword = passwordGenerator($_GET["maxLength"], $_GET["symReq"], $_GET["numReq"]); //Getting mnemonic image to aid memory #$url = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=".$newPassword[1]."%20".$newPassword[2]."&userip=INSERT-USER-IP"; // sendRequest #$ch = curl_init(); #curl_setopt($ch, CURLOPT_URL, $url); #curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); #curl_setopt($ch, CURLOPT_REFERER, "localhost"); #$body = curl_exec($ch); #curl_close($ch); //process the JSON string #$json = json_decode($body, TRUE); #$results = $json['responseData']['results'][0]; ?>
// once receive form submission if (isset($_POST['submit'])) { // form input validation, if invalid set to default number if (is_numeric($_POST["num_words"]) and $_POST["num_words"] >= $MIN_NUM_WORDS and $_POST["num_words"] <= $MAX_NUM_WORDS) { $num_words = $_POST["num_words"]; } $separator = $_POST["separator"]; $letter_case = $_POST["case"]; if (array_key_exists("add_random_number", $_POST)) { $random_number_end = $_POST["add_random_number"]; } if (array_key_exists("add_special_char", $_POST)) { $add_special_char = $_POST["add_special_char"]; } // call the passwordGenerator method to get the result $result = passwordGenerator($num_words, $separator, $letter_case, $random_number_end, $add_special_char); } // this is the function have the logic to generate a password function passwordGenerator($num_words, $separator, $letter_case, $random_number_end, $add_special_char) { $wordList = file("words.txt", FILE_IGNORE_NEW_LINES); $words_total_num = sizeof($wordList); $rand_words = ""; //array contains special chars $SPECIAL_CHARS = ['!', '@', '#', '$', '%', '^', '&', '*']; for ($i = 1; $i <= $num_words; $i++) { $rand_word_index = rand(0, $words_total_num); $rand_word_to_add = $wordList[$rand_word_index]; // call adjustCase function to adjust case as required $rand_word_to_add = adjustCase($letter_case, $rand_word_to_add); $rand_words .= $rand_word_to_add;