-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved unique identifier generation to lib/security
refs #9178
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
let _private = {}; | ||
|
||
// @TODO: replace with crypto.randomBytes | ||
_private.getRandomInt = function (min, max) { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
}; | ||
|
||
/** | ||
* Return a unique identifier with the given `len`. | ||
* | ||
* @param {Number} maxLength | ||
* @return {String} | ||
* @api private | ||
*/ | ||
module.exports.uid = function uid(maxLength) { | ||
var buf = [], | ||
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', | ||
charLength = chars.length, | ||
i; | ||
|
||
for (i = 0; i < maxLength; i = i + 1) { | ||
buf.push(chars[_private.getRandomInt(0, charLength - 1)]); | ||
} | ||
|
||
return buf.join(''); | ||
}; |
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