Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Explosion-Scratch/6ad74dc32b1d2c56642a95425268bf0b to your computer and use it in GitHub Desktop.
Save Explosion-Scratch/6ad74dc32b1d2c56642a95425268bf0b to your computer and use it in GitHub Desktop.
Generates passwords using a master password and the domain name.
(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