Created
November 28, 2021 23:40
-
-
Save Explosion-Scratch/6ad74dc32b1d2c56642a95425268bf0b to your computer and use it in GitHub Desktop.
Generates passwords using a master password and the domain name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
// canary.discord.com ⇒ discord.com | |
let hashed = await hash(`${location.hostname.split(".").slice(-2).join(".")} $ ${await passwd()}`); | |
navigator.clipboard.writeText(hashed); | |
[...document.querySelectorAll("input[type='password']")].forEach(i => (i.value = hashed)); | |
//Async hashes using crypto API 😎 | |
async function hash(string) { | |
// SHA-256 is better but generates too long passwords. | |
var buffer = await crypto.subtle.digest("SHA-1", new TextEncoder().encode(string)); | |
//Make it have some symbols and stuff | |
var chars = Array.prototype.map.call(new Uint8Array(buffer), ch => String.fromCharCode(ch)).join(''); | |
return btoa(chars); | |
}; | |
async function passwd() { | |
return new Promise(resolve => { | |
let container = document.createElement("div"); | |
container.setAttribute("style", "position: fixed; width: 100vw; height: 100vh; top: 0; left: 0; background: #0005; z-index: 1000; display: flex; justify-content: center; align-items: center;"); | |
container.innerHTML = `<input type='password' placeholder="Master password" autofocus style="padding: 15px; font-size: 16px; border-radius: 5px; background: white; color: #333; font-family: monospace; border: none; outline: none;">`; | |
document.body.appendChild(container); | |
document.activeElement.blur(); | |
container.querySelector("input").focus(); | |
container.addEventListener("keyup", (e) => { | |
if (e.key === "Enter") { | |
resolve(container.querySelector("input").value); | |
container.remove(); | |
} | |
}); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment