-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpassword.js
More file actions
45 lines (41 loc) · 1.9 KB
/
password.js
File metadata and controls
45 lines (41 loc) · 1.9 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
function generatePassword(key, site) {
var hashObj = new jsSHA(key + site + key, "TEXT");
return hashObj.getHash("SHA-256", "B64");
}
function breakingChangeAlert() {
// only show the alert for one year after the update
if (Math.floor((new Date()).getTime() / 1000) < 1726518238) {
// add div
document.getElementById("render_table").insertAdjacentHTML("afterend",
'<div style="background-color:yellow;width:40vw;"><b>Alert!</b><br />'+
'As of 2023-09-17, the generation strategy has been changed. To enable compatability mode '+
'(you probably want to do this for any password made before 2024), '+
'simply uncheck the "Enable modern generation strategy" box.<br />'+
'The previous strategy has been deprecated, and <em>may be removed at some point in the future</em>. '+
'It is highly recommended that you update any passwords that differ from the ones generated by the new strategy.'+
'<br />For more info, please check out the '+
'<a target="_blank" href="https://github.com/meta1203/PasswordMaker/blob/master/README.md">README</a>.'+
'</div>');
}
}
function domEdit() {
var key = document.getElementById("key").value;
var site = document.getElementById("site").value.toLowerCase();
var ret = "";
// modern generation strategy
// changed on 2023-09-17
// allowing me to make breaking changes while also
// ensuring backwards compatability for those who need it
if (document.getElementById("modern-version").checked) {
site = site.replaceAll(" ", "");
ret = generatePassword(key, site).substring(0, 16);
// ensure there is at least one special character in the
// generated password for improved site compatibility
if (!ret.includes("+") && !ret.includes("!"))
ret += "!";
} else {
ret = generatePassword(key, site).substring(0, 16);
}
document.getElementById("output").value = ret;
document.getElementById("output").select();
}