You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
514 B
19 lines
514 B
var RandomKeyGenerator = function(options) { |
|
if (!options) { |
|
options = {}; |
|
} |
|
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
}; |
|
|
|
// Generate a random key |
|
RandomKeyGenerator.prototype.createKey = function(keyLength) { |
|
var text = ''; |
|
var index; |
|
for (var i = 0; i < keyLength; i++) { |
|
index = Math.floor(Math.random() * this.keyspace.length); |
|
text += this.keyspace.charAt(index); |
|
} |
|
return text; |
|
}; |
|
|
|
module.exports = RandomKeyGenerator;
|
|
|