Skip to content

Instantly share code, notes, and snippets.

@michalkot
Created May 1, 2017 20:39
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 michalkot/cfcc2be996279f833b25c215b2bebcb3 to your computer and use it in GitHub Desktop.
Save michalkot/cfcc2be996279f833b25c215b2bebcb3 to your computer and use it in GitHub Desktop.
// Password generator bookmark.
// Fills in active text field OR all password fields if none is selected
// Run in chrome console, right click in bookmarks bar, select new page, paste in URL field
function passGen(n) {
let ar = new Uint32Array(n);
window.crypto.getRandomValues(ar);
ar = [...ar];
const pass = ar.map(n => n.toString(32)).join('-');
if (document.activeElement) document.activeElement.value = pass;
else [...document.querySelectorAll('input[type="password"]')].forEach(node => node.value = pass);
alert(pass);
}
copy(encodeURI(`javascript:(${passGen.toString()})(3)`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment