Skip to content

Instantly share code, notes, and snippets.

@gr0uch
Last active August 29, 2015 14:24
Show Gist options
  • Save gr0uch/ec5937b976be558e2ac3 to your computer and use it in GitHub Desktop.
Save gr0uch/ec5937b976be558e2ac3 to your computer and use it in GitHub Desktop.
/**
* Generate an ASCII password with a given length.
*
* @param {Number} [length] - Length of password, defaults to 18.
* @return {String}
*/
export default function generatePassword (length = 18) {
return String.fromCharCode(...Array.apply(null, Array(length))
// Allow all ASCII characters that can be input via a standard US keyboard,
// except for the space character.
.map(x => Math.floor(Math.random() * 93 + 33)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment