Skip to content

Instantly share code, notes, and snippets.

@juancri
Created October 26, 2018 05:46
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 juancri/905873f2efc202466a4da1c47b4c68df to your computer and use it in GitHub Desktop.
Save juancri/905873f2efc202466a4da1c47b4c68df to your computer and use it in GitHub Desktop.
// Dependencies
const Enumerable = require ('linq');
// Constants
const UPPER_CASE_CHARS = `ABCDEFGHIJKLMNOPQRSTUVWXYZ`;
const LOWER_CASE_CHARS = `abcdefghijklmnopqrstuvwxyz`;
const DIGITS = `0123456789`;
const SPECIAL_CHARS = `!@#$%^&*+=?/\\_`;
const VALID_CHARACTERS =
UPPER_CASE_CHARS + LOWER_CASE_CHARS +
DIGITS + SPECIAL_CHARS;
const LENGTH = 16;
// Generate
const pass = Enumerable
.range (0, LENGTH)
.select (() => Math.random () * VALID_CHARACTERS.length)
.select (r => Math.floor (r))
.select (r => VALID_CHARACTERS [r])
.toArray ()
.join ('');
// Done
console.log (pass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment