Merge pull request #2059 from rhelmer/bug844796-session-token-generation

mozilla bug 844796 - use node crypto module for randomString
This commit is contained in:
John McLear 2014-01-15 11:14:55 -08:00
commit 346c03911d

View file

@ -1,16 +1,13 @@
/** /**
* Generates a random String with the given length. Is needed to generate the Author, Group, readonly, session Ids * Generates a random String with the given length. Is needed to generate the Author, Group, readonly, session Ids
*/ */
var crypto = require('crypto');
var randomString = function randomString(len) var randomString = function randomString(len)
{ {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; crypto.randomBytes(48, function(ex, buf) {
var randomstring = ''; return buf.toString('hex');
for (var i = 0; i < len; i++) });
{
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
return randomstring;
}; };
module.exports = randomString; module.exports = randomString;