haste-server/lib/key_generators/random.js

15 lines
442 B
JavaScript
Raw Permalink Normal View History

var RandomKeyGenerator = function(options) {
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
};
// Generate a random key
RandomKeyGenerator.prototype.createKey = function(keyLength) {
var text = '';
for (var i = 0; i < keyLength; i++) {
text += this.keyspace.charAt(Math.floor(Math.random() * this.keyspace.length));
}
return text;
};
module.exports = RandomKeyGenerator;