-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
237 lines (185 loc) · 6.57 KB
/
script.js
File metadata and controls
237 lines (185 loc) · 6.57 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
const pwEl = document.getElementById("pw");
const copyEl = document.getElementById("copy");
const lenEl = document.getElementById("len");
const upperEl = document.getElementById("upper");
const lowerEl = document.getElementById("lower");
const numberEl = document.getElementById("number");
const symbolEl = document.getElementById("symbol");
const generateEl = document.getElementById("generate");
const saveBTN = document.getElementById("savePw");
const copyPW = document.getElementById("copyPw");
const searchPW = document.getElementById("searchPw");
const deleteBTN = document.getElementById("delete");
const upperLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowerLetters = "abcdefghijklmnopqrstuvwxyz";
const numbers = "0123456789";
const symbols = "!@#&()_+=";
function getPass(name) {
var pass = window.localStorage.getItem(name.toString());
if (pass == undefined || pass == null) {
return 'Password Not Found :|'
}
var bytes = CryptoJS.AES.decrypt(pass.toString(), 'Pass');
var decryptedPw = bytes.toString(CryptoJS.enc.Utf8);
var bytesTwo = CryptoJS.AES.decrypt(decryptedPw.toString(), 'Pass');
var decryptedPwTwo = bytesTwo.toString(CryptoJS.enc.Utf8);
var bytesThree = CryptoJS.AES.decrypt(decryptedPwTwo.toString(), 'Pass');
var decryptedPwThree = bytesThree.toString(CryptoJS.enc.Utf8);
var bytesFour = CryptoJS.AES.decrypt(decryptedPwThree.toString(), 'Pass');
var decryptedPwFour = bytesFour.toString(CryptoJS.enc.Utf8);
if (decryptedPwFour !== undefined && decryptedPwFour !== null) {
return decryptedPwFour;
} else {
return 'Password Not Found :|'
}
}
function getLowercase() {
return lowerLetters[Math.floor(Math.random() * lowerLetters.length)];
}
function getUppercase() {
return upperLetters[Math.floor(Math.random() * upperLetters.length)];
}
function getNumber() {
return numbers[Math.floor(Math.random() * numbers.length)];
}
function getSymbol() {
return symbols[Math.floor(Math.random() * symbols.length)];
}
function generatePassword() {
const len = lenEl.value;
let password = "";
if (upperEl.checked) {
password += getUppercase();
}
if (lowerEl.checked) {
password += getLowercase();
}
if (numberEl.checked) {
password += getNumber();
}
if (symbolEl.checked) {
password += getSymbol();
}
for (let i = password.length; i < len; i++) {
const x = generateX();
password += x;
}
pwEl.innerText = password;
}
function generateX() {
const xs = [];
if (upperEl.checked) {
xs.push(getUppercase());
}
if (lowerEl.checked) {
xs.push(getLowercase());
}
if (numberEl.checked) {
xs.push(getNumber());
}
if (symbolEl.checked) {
xs.push(getSymbol());
}
if (xs.length === 0) return "";
return xs[Math.floor(Math.random() * xs.length)];
}
function savePw() {
change();
var name = document.getElementById("pwName").value;
var pass = document.getElementById("pw");
name.toString()
name.toLowerCase()
pass.innerText.toString()
if (name != null && name != '' && name != ' ') {
if (pass.innerText !== 'Password' && pass.innerText !== 'Generate A Password First !!') {
var encryptedPw = CryptoJS.AES.encrypt(pass.innerText, 'Pass');
var encryptedPwTwo = CryptoJS.AES.encrypt(encryptedPw.toString(), 'Pass');
var encryptedPwThree = CryptoJS.AES.encrypt(encryptedPwTwo.toString(), 'Pass');
var encryptedPwFour = CryptoJS.AES.encrypt(encryptedPwThree.toString(), 'Pass');
window.localStorage.setItem(name, encryptedPwFour);
pass.innerText = 'Password Saved :D';
} else {
pass.innerText = 'Generate A Password First !!';
setTimeout(function() {
pass.innerText = 'Password';
}, 5000);
}
} else {
pass.innerText = 'Enter Password Name !!';
}
document.getElementById("pwName").value = '';
setTimeout(function() {
pass.innerText = 'Password';
}, 2000);
}
function searchPass() {
var name = document.getElementById("name").value;
var insert = document.getElementById("password");
name.toString()
name.toLowerCase()
insert.innerText = getPass(name);
document.getElementById("name").value = '';
if (insert.innerText == 'Password Not Found :|') {
setTimeout(function() {
insert.innerText = 'Search Password';
}, 2000);
}
if (insert.innerText !== 'Password Not Found :|') {
setTimeout(function() {
insert.innerText = 'Search Password';
}, 5000);
}
}
function deletePw() {
var name = document.getElementById("deletePw").value;
var status = document.getElementById("pwStatus");
var pass = window.localStorage.getItem(name);
if (pass != null && pass != undefined) {
window.localStorage.removeItem(name);
status.innerText = 'Password Deleted :D';
} else {
status.innerText = 'Password Not Found :|';
}
setTimeout(function() {
document.getElementById("deletePw").value = '';
status.innerText = 'Delete Password';
}, 2000);
}
generateEl.addEventListener("click", generatePassword);
saveBTN.addEventListener("click", savePw)
searchPW.addEventListener("click", searchPass)
deleteBTN.addEventListener("click", deletePw);
copyEl.addEventListener("click", () => {
const textarea = document.createElement("textarea");
const password = pwEl.innerText;
if (!password) {
return;
}
textarea.value = password;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
});
copyPW.addEventListener("click", () => {
const textarea = document.createElement("textarea");
const password = document.getElementById("password").innerText;
if (!password) {
return;
}
textarea.value = password;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
});
function change() {
var value = document.getElementById("len").value;
value.toString();
len = parseInt(value);
if (len > 15) {
document.getElementById("len").value = '15';
} else if (len < 4) {
document.getElementById("len").value = '4';
}
}