-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (41 loc) · 973 Bytes
/
app.js
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
const lowercase = 'abcdefghijklmnopqrstuvwxyz';
const uppercase = lowercase.toUpperCase();
const numbers = '0123456789';
const special = '!#$%&()*+,-./:;<=>?@[\]^_`{|}~'; // quotation marks and spaces excluded
let pass = [];
let type = lowercase;
function addChars(type)
{
let add = type.charAt(Math.round(Math.random() * ((type.length - 1) - 0 + 1)));
if (pass.includes(add) !== true)
{
pass = pass.concat(add);
}
else return;
}
// adds lowercase characters
while(pass.length < 12)
{
addChars(type);
}
// adds uppercase characters
type = uppercase;
while(pass.length < 16)
{
addChars(type);
}
// adds numbers
type = numbers;
while(pass.length < 20)
{
addChars(type);
}
// adds special characters
type = special;
while(pass.length < 25)
{
addChars(type);
}
let slice = pass;
slice = slice.sort((a, b) => {return 0.5 - Math.random()}); // shuffling the characters
console.log(slice.toString().split(',').join(''));