Created
June 25, 2020 13:23
-
-
Save lastguest/8fbd45eeef1160a43ae2677840174404 to your computer and use it in GitHub Desktop.
[JS] Generate random, custom length, alphanumerical token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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