fixed default character count calculation in the generator

This commit is contained in:
antelle 2021-04-01 21:57:42 +02:00
parent 58a85eabdf
commit c5946b1a0b
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
1 changed files with 11 additions and 3 deletions

View File

@ -46,10 +46,18 @@ const PasswordGenerator = {
};
const pattern = opts.pattern || 'X';
const rangeIxRandomBytes = kdbxweb.Random.getBytes(opts.length);
const rangeCharRandomBytes = kdbxweb.Random.getBytes(opts.length);
const defaultRangeGeneratedChars = [];
let countDefaultChars = 0;
for (let i = 0; i < opts.length; i++) {
const patternChar = pattern[i % pattern.length];
if (patternChar === 'X') {
countDefaultChars++;
}
}
const rangeIxRandomBytes = kdbxweb.Random.getBytes(countDefaultChars);
const rangeCharRandomBytes = kdbxweb.Random.getBytes(countDefaultChars);
const defaultRangeGeneratedChars = [];
for (let i = 0; i < countDefaultChars; i++) {
const rangeIx = i < ranges.length ? i : rangeIxRandomBytes[i] % ranges.length;
const range = ranges[rangeIx];
const char = range[rangeCharRandomBytes[i] % range.length];