Skip to content

Commit

Permalink
Allow overrideMaxTrial on internalGeneratePasswordWithSource
Browse files Browse the repository at this point in the history
  • Loading branch information
pkong-ds committed Aug 28, 2024
1 parent c63e644 commit b675e0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions portal/src/util/passwordGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ describe("passwordGenerator", () => {
},
};
};

const OVERRIDE_MAX_TRIAL = 25; // ref PR#4666
const [password, attempts] = internalGeneratePasswordWithSource(
createRandSource(),
{
digit_required: true,
excluded_keywords: ["0"],
}
},
OVERRIDE_MAX_TRIAL
);
expect(password).not.toBeNull();
expect(password).not.toContain("0");
Expand Down
8 changes: 5 additions & 3 deletions portal/src/util/passwordGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AllCharLists = [
CharListSymbol,
];

const MaxTrials = 25;
const MaxTrials = 10;
const DefaultMinLength = 8;
const GuessableEnabledMinLength = 32;

Expand Down Expand Up @@ -74,9 +74,11 @@ export function generatePasswordWithSource(

export function internalGeneratePasswordWithSource(
source: RandSource,
policy: PasswordPolicyConfig
policy: PasswordPolicyConfig,
overrideMaxTrials?: number
): [string | null, number] {
for (let i = 0; i < MaxTrials; i++) {
const maxTrials = overrideMaxTrials ?? MaxTrials;
for (let i = 0; i < maxTrials; i++) {
const password = generatePasswordOnce(source, policy);
if (password !== null) {
return [password, i];
Expand Down

0 comments on commit b675e0d

Please sign in to comment.