Remove "binning" from password generation

This commit is contained in:
Grant Moyer 2019-11-12 20:39:08 -05:00
parent a65d7208c7
commit b1da50133b
1 changed files with 6 additions and 4 deletions

View File

@ -1,6 +1,5 @@
import kdbxweb from 'kdbxweb';
import { phonetic } from 'util/generators/phonetic';
import { shuffle } from 'util/fn';
const PasswordGenerator = {
charRanges: {
@ -39,14 +38,17 @@ const PasswordGenerator = {
if (!ranges.length) {
return '';
}
const pool = [];
for (let i = 0; i < ranges.length; i++) {
pool.push(...ranges[i]);
}
const randomBytes = kdbxweb.Random.getBytes(opts.length);
const chars = [];
for (let i = 0; i < opts.length; i++) {
const range = ranges[i % ranges.length];
const rand = Math.round(Math.random() * 1000) + randomBytes[i];
chars.push(range[rand % range.length]);
chars.push(pool[rand % pool.length]);
}
return shuffle(chars).join('');
return chars.join('');
},
generateMac() {