-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
158 lines (134 loc) · 4.46 KB
/
script.js
File metadata and controls
158 lines (134 loc) · 4.46 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
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
const upperCaseinput = document.getElementById("upperCase");
const lowerCaseinput = document.getElementById("lowerCase");
const incNumbers = document.getElementById("incNumbers");
const incSymbols = document.getElementById("incSymbols");
const rangeValue = document.getElementById("rangeValue");
const randompass = document.querySelector(".randompass");
const myRange = document.getElementById("myRange");
const generaBtn = document.querySelector(".Generate");
const passLevel = document.getElementById("passlevel");
const faCopy = document.querySelector(".fa-copy");
faCopy.addEventListener("click", () => {
const textaArea = document.createElement("textarea");
const password = randompass.innerText;
if (!password) {
return;
}
textaArea.value = password;
document.body.appendChild(textaArea);
textaArea.select();
document.execCommand("copy");
textaArea.remove();
const notyf = new Notyf();
notyf.success({
message: `Copy ${password}`,
duration: 1500,
position: {
x: "center",
y: "top",
},
});
});
const randomFunc = {
lower: getrandomLower,
upper: getrandomUpper,
number: getRandomNumber,
symbols: getSymbol,
};
function getrandomLower() {
return String.fromCharCode(Math.floor(Math.random() * 26) + 97);
}
function getrandomUpper() {
return String.fromCharCode(Math.floor(Math.random() * 26) + 65);
}
function getRandomNumber() {
return String.fromCharCode(Math.floor(Math.random() * 10) + 48);
}
function getSymbol() {
const symbols = "!@#$%^&*(){}[]=<>/,.";
return symbols[Math.floor(Math.random() * symbols.length)];
}
generaBtn.addEventListener("click", () => {
faCopy.style.display = "flex";
const length = +myRange.value;
const hasLower = lowerCaseinput.checked;
const hasUpper = upperCaseinput.checked;
const hasNumber = incNumbers.checked;
const hasSymbols = incSymbols.checked;
randompass.innerText = generatePassword(
hasLower,
hasUpper,
hasNumber,
hasSymbols,
length
);
});
function generatePassword(lower, upper, number, symbols, length) {
let generatePass = "";
const typesCount = lower + upper + number + symbols; // checked durumundan donen sonucu aldim
const typesArr = [{ lower }, { upper }, { number }, { symbols }].filter(
(type) => Object.values(type)[0] //secili olanlari aldim
);
if (typesCount === 0) {
randompass.innerText = "Verify a condition!";
randompass.style.color = "red";
faCopy.style.display = "none";
setTimeout(() => {
randompass.innerText = "P4$5W0rD!";
randompass.style.color = "#a4ffaf";
}, 1500);
return randompass.textContent;
}
for (let i = 0; i < length; i += typesCount) {
typesArr.forEach((type) => {
const funcName = Object.keys(type)[0];
generatePass += randomFunc[funcName]();
});
}
const finalPass = generatePass.slice(0, length);
return finalPass;
}
function updateValue() {
var range = document.getElementById("myRange");
var value = range.value;
document.getElementById("rangeValue").innerText = value;
const li1 = document.querySelector(".levelInput ul li:nth-child(1)");
const li2 = document.querySelector(".levelInput ul li:nth-child(2)");
const li3 = document.querySelector(".levelInput ul li:nth-child(3)");
const li4 = document.querySelector(".levelInput ul li:nth-child(4)");
if (value < 5) {
li1.style.backgroundColor = "#8ccb35";
li2.style.backgroundColor = "";
li3.style.backgroundColor = "";
li4.style.backgroundColor = "";
passLevel.textContent = "Too Weak";
passLevel.style.color = "#8ccb35";
} else if (value >= 5 && value < 15) {
li1.style.backgroundColor = "#e1a91a";
li2.style.backgroundColor = "#e1a91a";
li3.style.backgroundColor = "";
li4.style.backgroundColor = "";
passLevel.textContent = "MEDIUM";
passLevel.style.color = "#e1a91a";
} else if (value > 16) {
li1.style.backgroundColor = "red";
li2.style.backgroundColor = "red";
li3.style.backgroundColor = "red";
li4.style.backgroundColor = "red";
} else if (value >= 15) {
li1.style.backgroundColor = "red";
li2.style.backgroundColor = "red";
li3.style.backgroundColor = "red";
passLevel.textContent = "Difficult";
passLevel.style.color = "red";
}
}
document.getElementById("myRange").addEventListener("input", updateValue);
const range = document.getElementById("myRange");
const updateRange = () => {
myRange.addEventListener("input", () => {
updateValue();
generaBtn.click();
});
};
updateRange();