mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-23 17:50:19 +01:00
Update dictionary.js
This commit is contained in:
parent
e54a860172
commit
8e9205cecc
1 changed files with 8 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
var rand = require('random-js');
|
var rand = require('random-js');
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
var dictionary;
|
var dictionary;
|
||||||
var randomEngine;
|
var randomEngine = rand.engines.nativeMath;
|
||||||
var random;
|
var random;
|
||||||
|
|
||||||
var DictionaryGenerator = function(options) {
|
var DictionaryGenerator = function(options) {
|
||||||
|
@ -14,15 +14,13 @@ var DictionaryGenerator = function(options) {
|
||||||
//Load dictionary
|
//Load dictionary
|
||||||
fs.readFile(options.path, 'utf8', (err,data) => {
|
fs.readFile(options.path, 'utf8', (err,data) => {
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
dictionary = data.split(',');
|
this.dictionary = data.split(',');
|
||||||
|
|
||||||
//Remove any non alpha-numeric characters
|
//Remove any non alpha-numeric characters
|
||||||
for(var i = 0; i < dictionary.length; i++){
|
for(var i = 0; i < this.dictionary.length; i++)
|
||||||
dictionary[i] = dictionary[i].replace(/\W/g,'');
|
this.dictionary[i] = this.dictionary[i].replace(/\W/g,'');
|
||||||
}
|
|
||||||
|
|
||||||
random = rand.integer(0,dictionary.length);
|
this.random = rand.integer(0, this.dictionary.length);
|
||||||
randomEngine = rand.engines.nativeMath;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +28,7 @@ var DictionaryGenerator = function(options) {
|
||||||
DictionaryGenerator.prototype.createKey = function(keyLength) {
|
DictionaryGenerator.prototype.createKey = function(keyLength) {
|
||||||
var text = '';
|
var text = '';
|
||||||
for(var i = 0; i < keyLength; i++)
|
for(var i = 0; i < keyLength; i++)
|
||||||
text += dictionary[random(randomEngine)];
|
text += this.dictionary[random(randomEngine)];
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue