Skip to content

Instantly share code, notes, and snippets.

@lastguest
Created June 25, 2020 13:23
Show Gist options
  • Save lastguest/8fbd45eeef1160a43ae2677840174404 to your computer and use it in GitHub Desktop.
Save lastguest/8fbd45eeef1160a43ae2677840174404 to your computer and use it in GitHub Desktop.
[JS] Generate random, custom length, alphanumerical token
function randomToken(length){
const crypto = require("crypto");
let token = "";
for (let i = length >> 2 ; i >= 0 ; i--) token += crypto.randomBytes(4).readUInt32LE().toString(36);
return token, token.substr(0,length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment