-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
49 lines (39 loc) · 1.59 KB
/
script.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
function createPassword() {
const seed = document.querySelector("#seed").value
const service = document.querySelector("#service").value
document.querySelector("#passphrase").value = generatePassword(seed, service)
document.querySelector(".result").style.display = "block"
document.querySelector(".result label").innerText = `Password for ${service}`
}
function createPassphrase() {
const seed = document.querySelector("#seed").value
const service = document.querySelector("#service").value
document.querySelector("#passphrase").value = generatePassphrase(
seed,
service
);
document.querySelector(".result").style.display = "block"
document.querySelector(".result label").innerText = `Password for ${service}`
}
function generatePassphrase(seed, service) {
const combo = (service + seed).toLowerCase()
const hashObject = MD5(combo)
const digitList = hashObject.replace(/\D/g, "").match(/.{1,4}/g)
const words = []
for (let x of digitList) {
words.push(wordList()[parseInt(x) % 2048])
}
let generated = words.slice(0, 4).join("-")
generated = `${generated.charAt(0).toUpperCase()}${generated.slice(1)}-${(digitList[4] % 10)}`
return generated
}
function generatePassword(seed, service) {
const specialCharacters = "!@#$%^&*()/"
const combo = service.toLowerCase() + seed.toLowerCase()
const hashObject = MD5(combo)
let generated = specialCharacters[service.length % 10]
generated += hashObject.substr(0, 7).toUpperCase()
generated += hashObject.substr(8, 7).toLowerCase()
generated += specialCharacters[10 - (service.length % 10)]
return generated
}