mirror of
https://github.com/toptal/haste-server.git
synced 2024-11-30 13:14:01 +01:00
18 lines
482 B
JavaScript
18 lines
482 B
JavaScript
var RandomKeyGenerator = function(options) {
|
|
if (!options) {
|
|
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;
|