Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // generateToken
- // This function generates a random string at a length specified by passing in the n parameter
- // Customise chars to define the available characters to add to the string
- // Usage: generateToken(32);
- function generateToken(n: 32) {
- var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- var token = '';
- if (!isNaN(n)) {
- for(var i = 0; i < n; i++) {
- token += chars[Math.floor(Math.random() * chars.length)];
- }
- return token;
- } else {
- console.log("Failed to generate token because the length specified must be a valid number.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement