mirror of
https://github.com/SunRed/haste-server.git
synced 2024-12-27 22:50:11 +01:00
Updated dictionary.js
Now expects a newline separated dictionary, supports both \n and \n\r
This commit is contained in:
parent
ac2bceefbb
commit
80f0618736
1 changed files with 7 additions and 9 deletions
|
@ -11,20 +11,18 @@ var DictionaryGenerator = function(options) {
|
|||
//Load dictionary
|
||||
fs.readFile(options.path, 'utf8', (err,data) => {
|
||||
if(err) throw err;
|
||||
this.dictionary = data.split(',');
|
||||
|
||||
//Remove any non alpha-numeric characters
|
||||
for(var i = 0; i < this.dictionary.length; i++)
|
||||
this.dictionary[i] = this.dictionary[i].replace(/\W/g,'');
|
||||
|
||||
});
|
||||
this.dictionary = data.split(/[\n\r]+/);
|
||||
});
|
||||
};
|
||||
|
||||
//Generates a dictionary-based key, of keyLength words
|
||||
DictionaryGenerator.prototype.createKey = function(keyLength) {
|
||||
var text = '';
|
||||
for(var i = 0; i < keyLength; i++)
|
||||
text += this.dictionary[Math.floor(Math.random()*this.dictionary.length)];
|
||||
for(var i = 0; i < keyLength; i++) {
|
||||
var index =Math.floor(Math.random()*this.dictionary.length);
|
||||
text += this.dictionary[index];
|
||||
}
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue