forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_password.js
More file actions
45 lines (40 loc) · 1.68 KB
/
check_password.js
File metadata and controls
45 lines (40 loc) · 1.68 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
const Mellt = require('./lib/Mellt/Mellt');
const localize = require('./localize').localize;
const checkPassword = (password_selector) => {
const el_password = document.querySelector(password_selector);
if (!el_password) {
return;
}
const div = el_password.parentNode.querySelector('.days_to_crack') || document.createElement('div');
const daysToCrack = Mellt.checkPassword(el_password.value.trim());
if (daysToCrack < 0) {
div.textContent = localize('The password you entered is one of the world\'s most commonly used passwords. You should not be using this password.');
} else {
let years;
if (daysToCrack > 365) {
years = Math.round(daysToCrack / 365 * 10) / 10;
if (years > 1000000) {
years = `${Math.round(years / 1000000 * 10) / 10} ${localize('million')}`;
} else if (years > 1000) {
years = `${Math.round(years / 1000)} ${localize('thousand')}`;
}
}
div.textContent = localize(
'Hint: it would take approximately [_1][_2] to crack this password.', [
(daysToCrack === 1000000000 ? '>' : ''),
years ? `${years} ${localize('years')}` : `${daysToCrack} ${localize('days')}`,
]);
}
div.className = `days_to_crack fill-bg-color hint ${daysToCrack < 30 ? 'red' : 'green'}`;
el_password.parentNode.appendChild(div);
};
const removeCheck = (password_selector) => {
const el_message = document.querySelector(password_selector).parentNode.querySelector('.days_to_crack');
if (el_message) {
el_message.remove();
}
};
module.exports = {
removeCheck,
checkPassword,
};