1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-27 11:20:18 +01:00
haste-server/lib/key_generators/random.js

21 lines
489 B
JavaScript
Raw Normal View History

module.exports = class RandomKeyGenerator {
2020-08-28 04:39:03 +02:00
// Initialize a new generator with the given keySpace
constructor(options = {}){
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
}
2020-08-28 04:39:03 +02:00
// Generate a key of the given length
createKey(keyLength){
let text = '';
2020-08-28 04:39:03 +02:00
for (let i = 0; i < keyLength; i++){
const index = Math.floor(Math.random() * this.keyspace.length);
text += this.keyspace.charAt(index);
}
2020-08-28 04:39:03 +02:00
return text;
}
};