-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker.js
executable file
·66 lines (58 loc) · 2.03 KB
/
checker.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
let currentRequest = false;
function hookPasswordFields() {
// $("input:password").on("input", changeListener);
$("[type=password]").on("input", changeListener);
}
function statusNeutral(target) {
target.removeClass("passwordCheckerStatusPass passwordCheckerStatusFail");
}
function statusPass(target) {
target.removeClass("passwordCheckerStatusFail");
target.addClass("passwordCheckerStatusPass");
}
function statusFail(target) {
target.removeClass("passwordCheckerStatusPass");
target.addClass("passwordCheckerStatusFail");
}
function changeListener(event) {
let pswdField = $(event.target),
val = pswdField.val();
if (!val) {
statusNeutral(pswdField);
} else {
statusNeutral(pswdField);
let sha = sha1(val).toUpperCase(),
shaPrefix = sha.substring(0, 5),
shaSuffix = sha.substring(5);
if (currentRequest) currentRequest.abort();
currentRequest = $.get(
"https://api.pwnedpasswords.com/range/" + shaPrefix,
"",
(data, textStatus, jqXHR) => {
currentRequest = false;
if (textStatus !== "success") {
alert("Something went wrong with the Password Breach Checker. Please contact the developer with details.");
return;
}
let results = data.split("\n");
if (results.filter(x => x.split(":")[0] == shaSuffix).length) {
statusFail(pswdField);
} else {
statusPass(pswdField);
}
}
);
}
}
let observer = new MutationObserver((mutations, observer) => {
// This function fires whenever the DOM changes.
hookPasswordFields();
});
// define what element should be observed by the observer
// and what types of mutations trigger the callback
observer.observe(document, {
subtree: true,
childList: true
});
hookPasswordFields();