mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
parent
411ce69006
commit
72911862e7
28
ghost/security/lib/identifier.js
Normal file
28
ghost/security/lib/identifier.js
Normal file
@ -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('');
|
||||
};
|
@ -11,5 +11,9 @@ module.exports = {
|
||||
|
||||
get string() {
|
||||
return require('./string');
|
||||
},
|
||||
|
||||
get identifier() {
|
||||
return require('./identifier');
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user