-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.php
More file actions
111 lines (107 loc) · 3.03 KB
/
generator.php
File metadata and controls
111 lines (107 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
//Set default password values
$wordsErr = '';
$num_words = 4;
$link = '-';
$symbol = 'no';
$number = 'no';
//Server side validation
if (isset($_GET["submit"])) {
if (ctype_digit($_GET["words"])) {
$num_words = $_GET["words"];
}
else {
$wordsErr = "You must enter a number";
}
if ($_GET['link'] != '') {
$link = $_GET['link'];
}
if ($_GET['symbol'] == 'yes') {
$symbol = $_GET['symbol'];
}
if ($_GET['number'] == 'yes') {
$number = $_GET['number'];
}
}
//Scrapes plain text from inside <li> tags
//Modified from http://stackoverflow.com/questions/14329892/web-scrape-using-preg-match-all
function get_words($url){
$site = file_get_contents($url);
$dom = new DOMDocument();
@$dom->loadHTML($site);
$result = array();
foreach($dom->getElementsByTagName('li') as $li) {
$innerHTML= '';
$children = $li->childNodes;
foreach ($children as $child) {
$innerHTML .= trim($child->ownerDocument->saveXML($child));
}
$fixed = array_map('strip_tags', array_map('trim', explode("<br/>",trim($innerHTML))));
foreach($fixed as $val){
if(empty($val)){continue;}
$str = (string)$val;
$result[] = str_replace(array('! '),'',$str);
}
}
return $result;
}
//Scrape words from a dictionary site
//Site is saved so as not to leverage their resources
$array_words = [];
for ($x = 1; $x <= 10; $x++) {
$z=$x*2;
$y=$z-1;
//Formats in accordance with URL pattern
if ($y < 10)
$y='0'.$y;
if ($z < 10)
$z='0'.$z;
$url = 'dictionary/words-'.$y.'-'.$z.'-hundred.html';
//Scrape the given URL's
$new_words = get_words($url);
//Create an array or words
$array_words = array_merge($array_words, $new_words);
}
//Generate 5 passwords and store in an array
$password_array = array();
for ($a = 0; $a < 5; $a++) {
$password = '';
//Select a random words
for ($i = 0; $i <= $num_words; $i++) {
$word_index = rand(0, count($array_words));
$word = (string)$array_words[$word_index];
$password = $password.$word.$link;
}
//Add number
if ($number == 'yes') {
$rand_int = (string)rand(0, 9);
$password = $password.$rand_int;
}
//Add symbol
if ($symbol == 'yes') {
$chars = array(
0 => '!',
1 => '@',
2 => '#',
3 => '$',
4 => '%',
5 => '^',
6 => '&',
7 => '*',
8 => '(',
9 => ')',
10 => '?'
);
$rand_int = rand(0, 10);
$rand_char = $chars[$rand_int];
$password = $password.$rand_char;
}
//Remove extra link if nor additional numbers or strings are added
if ($symbol != 'yes' && $number != 'yes') {
$password = substr($password, 0, -1);
}
//Remove spaces
$password = preg_replace('/[\s]/','',$password);
//Append password to password array
array_push($password_array, $password);
}