Skip to content

Instantly share code, notes, and snippets.

@boscomonkey
Last active November 12, 2021 22:28
Show Gist options
  • Save boscomonkey/33f71154d4caa1c1f46ac7b8066add2d to your computer and use it in GitHub Desktop.
Save boscomonkey/33f71154d4caa1c1f46ac7b8066add2d to your computer and use it in GitHub Desktop.
Bookmarklet to take XKCD password - https://preshing.com/20110811/xkcd-password-generator/ - and turn it into caps, special chars (periods), and numbers.
(
function() {
function massage_xkcd(txt) {
const arry = txt.split(' ');
const randNum = String(Math.random()).slice(2, 5);
const caps = arry.map(word => word.charAt(0).toUpperCase() + word.substring(1));
caps.push(randNum);
return caps.join('.');
}
const elt = document.getElementById('xkcd_pw_gen_result');
const txt = elt.innerText;
const passwd = massage_xkcd(txt);
alert(passwd);
}
)()
@boscomonkey
Copy link
Author

Revision 2 uses a much clearer way of generating 3 digits (with leading zeros if necessary):

String(Math.random()).slice(2, 5)

instead of the old opaque way:

Math.floor(Math.random()*(999-100+1)+100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment