1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2025-09-04 04:50:14 +02:00

Rewrote key generator tests, fixed vowels

-Tests were not brought up to date with some updates that were done to key generator modules.
-Apparently original creator had no idea that 'y' is a vowel; fixed this issue and reflected changes in actual files.
This commit is contained in:
zneix 2020-09-23 01:07:32 +02:00
parent d2c5641886
commit 7808ccf009
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 911916E0523B22F6
7 changed files with 55 additions and 65 deletions

View file

@ -3,21 +3,22 @@ const fs = require('fs');
module.exports = class DictionaryGenerator {
constructor({ path } = {}, readyCallback){
constructor({ path } = {}){
//check for dictionary path
if (!path){
winston.error('No dictionary path specified in options');
process.exit(1);
let error = 'No dictionary path specified in options';
winston.error(error);
throw error;
}
//load dictionary
if (!fs.existsSync(path)){
winston.error(`Dictionary file "${path}" doesn't exist`);
process.exit(1);
let error = `Dictionary file "${path}" doesn't exist`;
winston.error(error);
throw error;
}
this.dictionary = fs.readFileSync(path).toString().split(/\s+/gm);
if (readyCallback) readyCallback();
}
// Generates a dictionary-based key, of keyLength words

View file

@ -1,18 +1,20 @@
//inspiration from pwgen and https://tools.arantius.com/password
//helper function to get a random consonant / vowel
//helper function to get a random array element
function randArray(collection){
return collection[ Math.floor(Math.random() * collection.length) ];
}
const vovels = 'aeiou';
const consonants = 'bcdfghjklmnpqrstvwxyz';
const vovels = 'aeiouy';
const consonants = 'bcdfghjklmnpqrstvwxz';
module.exports = class PhoneticKeyGenerator {
//generate a phonetic key consisting of random consonant & vowel
createKey(keyLength){
let text = '';
const start = Math.floor(Math.random() * 2);
//start == 0 - starts with consonant
//start == 1 - starts with vovel
for (let i = 0; i < keyLength; i++){
text += randArray(i % 2 == start ? consonants : vovels);