Skip to content

Commit b494095

Browse files
authored
Merge pull request bartificer#64 from pricemi115/dev_issue37_statsupdate
Issue bartificer#37: Stats Update
2 parents abb4536 + 3722b07 commit b494095

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

src/lib/statistics.mjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -561,21 +561,21 @@ class Statistics {
561561
* @private
562562
*/
563563
__passwordStrength(stats) {
564-
const minEntropyBlind = stats.minEntropyBlind;
565-
const entropySeen = stats.entropySeen;
564+
const minEntropyBlind = stats.minEntropyBlind.value;
565+
const entropySeen = stats.entropySeen.value;
566566

567567
const entropyBlindThreshold = this.#entropyBlindThreshold;
568568
const entropySeenThreshold = this.#entropySeenThreshold;
569569

570570
// mix of good and bad
571571
let passwordStrength = 'OK';
572572

573-
if (minEntropyBlind >= entropyBlindThreshold &&
574-
entropySeen >= entropySeenThreshold) {
573+
if ((minEntropyBlind >= entropyBlindThreshold) &&
574+
(entropySeen >= entropySeenThreshold)) {
575575
// all good
576576
passwordStrength = 'GOOD';
577-
} else if (minEntropyBlind < entropyBlindThreshold &&
578-
entropySeen < entropySeenThreshold) {
577+
} else if ((minEntropyBlind < entropyBlindThreshold) &&
578+
(entropySeen < entropySeenThreshold)) {
579579
// all bad
580580
passwordStrength = 'POOR';
581581
}

src/lib/statistics.test.mjs

+8-8
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ describe('Test class Statistics', () => {
406406
test('with poor password strength', () => {
407407
// these are just the entropies
408408
const stats = {
409-
entropyBlind: 179,
410-
minEntropyBlind: 20,
411-
maxEntropyBlind: 215,
412-
entropySeen: 20,
409+
entropyBlind: {value: 179},
410+
minEntropyBlind: {value: 20},
411+
maxEntropyBlind: {value: 215},
412+
entropySeen: {value: 20},
413413
};
414414

415415
expect(me.__passwordStrength(stats)).toBe('POOR');
@@ -418,10 +418,10 @@ describe('Test class Statistics', () => {
418418
test('with good password strength', () => {
419419
// these are just the entropies
420420
const stats = {
421-
entropyBlind: 179,
422-
minEntropyBlind: 143,
423-
maxEntropyBlind: 215,
424-
entropySeen: 60,
421+
entropyBlind: {value: 179},
422+
minEntropyBlind: {value: 143},
423+
maxEntropyBlind: {value: 215},
424+
entropySeen: {value: 60},
425425
};
426426

427427
expect(me.__passwordStrength(stats)).toBe('GOOD');

src/lib/xkpasswd.mjs

+7-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class XKPasswd {
5252
setPreset(preset) {
5353
this.#preset = new Presets(preset);
5454
this.#config = this.#preset.config();
55+
56+
// Refresh the statistics
57+
this.#statsClass = new Statistics(this.#config);
5558
}
5659

5760
/**
@@ -169,7 +172,7 @@ class XKPasswd {
169172
num = 1;
170173
}
171174
const passwords = [];
172-
for (let i = 0; i < num ; i++) {
175+
for (let i = 0; i < num; i++) {
173176
passwords.push(this.password());
174177
}
175178

@@ -280,21 +283,23 @@ class XKPasswd {
280283
* @private
281284
*/
282285
__randomWords() {
283-
284286
const numWords = this.#config.num_words;
285287
const maxDict = this.#dictionary.getLength();
286288

287289
log.trace(`__randomwords, mindict: ${this.#dictionary.getMinWordLength()}
288290
maxdict: ${this.#dictionary.getMaxWordLength()}`);
289291
// get the minimum of the 2 input variables and the longest dictionary word
292+
// eslint-disable-next-line max-len
290293
let minLength = Math.min(this.#config.word_length_min, this.#config.word_length_max, this.#dictionary.getMaxWordLength());
291294

292295
// get the maximum of the 2 input variables and the shortest dictionary word
296+
// eslint-disable-next-line max-len
293297
let maxLength = Math.max(this.#config.word_length_min, this.#config.word_length_max, this.#dictionary.getMinWordLength());
294298

295299
minLength = Math.max(minLength, this.#dictionary.getMinWordLength());
296300
maxLength = Math.min(maxLength, this.#dictionary.getMaxWordLength());
297301

302+
// eslint-disable-next-line max-len
298303
log.trace(`about to generate ${numWords} words ${minLength} - ${maxLength}`);
299304

300305
const list = [];

src/web/settingscontroller.mjs

+4-3
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ class SettingsController {
7676
settings.sep_before_after = parseInt(settings.sep_before_after);
7777
settings.padding_digits_before = parseInt(settings.padding_digits_before);
7878
settings.padding_digits_after = parseInt(settings.padding_digits_after);
79+
// eslint-disable-next-line max-len
7980
settings.padding_characters_before = parseInt(settings.padding_characters_before);
81+
// eslint-disable-next-line max-len
8082
settings.padding_characters_after = parseInt(settings.padding_characters_after);
8183
settings.pad_to_length = parseInt(settings.pad_to_length);
8284

8385
this.#model.setPreset({
8486
description: 'Custom preset',
85-
config: settings
86-
});
87-
}
87+
config: settings});
88+
};
8889

8990
/**
9091
* Prepare the config object as retrieved from XKPasswd library

0 commit comments

Comments
 (0)