-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
168 lines (134 loc) · 5.55 KB
/
index.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!doctype html>
<html lang="en" class="h-100">
<head>
<title>PSWD — anonymous generator of strong passwords.</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.6.1/font/bootstrap-icons.css">
</head>
<body class="h-100">
<div class="p-1 h-100 d-flex flex-column justify-content-center">
<div class="container">
<div class="row">
<div class="col-md-6 col-xl-4 mx-auto text-center">
<div class="input-group mb-3 mb-md-4 mb-xl-5">
<h1>PSWD</h1>
<select class="form-control form-control-lg form-select" id="strength">
<option value="8">8 (WEAK)</option>
<option value="16" selected>16 (NORMAL)</option>
<option value="24">24 (STRONG)</option>
</select>
<button class="btn btn-danger" type="button" id="generate" onclick="generate(); return false;">
<i class="bi bi-arrow-clockwise"></i> GENERATE
</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-xl-8 mx-auto text-center">
<div class="input-group mb-3 mb-md-4 mb-xl-5">
<input id="pswd" class="form-control form-control-lg fs-1 font-monospace" type="text" placeholder="PASSWORD" readonly>
<button class="btn btn-primary fs-1" type="button" id="copy" onclick="copy(); return false;">
<span class="px-1">
<i class="bi bi-files"></i><span class="d-none d-md-inline"> COPY </span>
</span>
</button>
</div>
<a class="btn btn-outline-light btn-sm mb-2" href="//github.com/yepteam/pswd" target="_blank"><i class="bi bi-github"></i> GITHUB </a>
</div>
</div>
</div>
</div>
<script>
function copy() {
var text = document.querySelector('#pswd');
text.focus();
text.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
//console.log('Copying text command was ' + msg);
}
catch (err) {
//console.log('Oops, unable to copy');
}
}
function shuffle(string) {
let array = string.split('');
var m = array.length, t, i;
// While there remain elements to shuffle…
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
string = array.join('');
return string;
}
function generate() {
let strength = document.getElementById('strength').value || 8;
let result = '';
let uppercase = shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
let lowercase = shuffle('abcdefghijklmnopqrstuvwxyz');
let numbers = shuffle('0123456789');
let special = shuffle('!@#$%^&-');
for ( let i = 0; i < strength; i++ ) {
if (i % 4 == 0) {
let uppercaseRandomIndex = Math.floor(Math.random() * uppercase.length);
let uppercaseRandomSymbol = uppercase.charAt(uppercaseRandomIndex);
while (result.includes(uppercaseRandomSymbol)) {
uppercaseRandomIndex = Math.floor(Math.random() * uppercase.length);
uppercaseRandomSymbol = uppercase.charAt(uppercaseRandomIndex);
}
result += uppercaseRandomSymbol;
}
else {
if (i % 3 == 0) {
let lowercaseRandomIndex = Math.floor(Math.random() * lowercase.length);
let lowercaseRandomSymbol = lowercase.charAt(lowercaseRandomIndex);
while (result.includes(lowercaseRandomSymbol)) {
lowercaseRandomIndex = Math.floor(Math.random() * lowercase.length);
lowercaseRandomSymbol = lowercase.charAt(lowercaseRandomIndex);
}
result += lowercaseRandomSymbol;
}
else {
if (i % 2 == 0) {
let specialRandomIndex = Math.floor(Math.random() * special.length);
let specialRandomSymbol = special.charAt(specialRandomIndex);
while (result.includes(specialRandomSymbol)) {
specialRandomIndex = Math.floor(Math.random() * special.length);
specialRandomSymbol = special.charAt(specialRandomIndex);
}
result += specialRandomSymbol;
}
else {
let numbersRandomIndex = Math.floor(Math.random() * numbers.length);
let numbersRandomSymbol = numbers.charAt(numbersRandomIndex);
while (result.includes(numbersRandomSymbol)) {
numbersRandomIndex = Math.floor(Math.random() * numbers.length);
numbersRandomSymbol = numbers.charAt(numbersRandomIndex);
}
result += numbersRandomSymbol;
}
}
}
}
//result = shuffle(result);
document.getElementById('pswd').value = result;
return result;
}
function onchange(e) {
generate();
}
generate();
document.getElementById('strength').addEventListener('change', onchange);
</script>
</body>
</html>