App crash when generating passwords with a large list of excluded characters
Current behavior
The application exhibits two distinct issues depending on the "Exclude characters" input:
Total Crash: When providing a long list of specific characters to exclude (e.g., @, :, /, %, &, ?, #, +, !, $, ^, *), the application crashes immediately upon clicking "Generate password(s)".
Incorrect Output: When using a shorter exclusion filter such as ^, *, the generator fails to produce a random string and instead returns only strings of asterisks (*) regardless of the configured password length.
How to reproduce it (as minimally and precisely as possible)
Scenario 1: App Crash
-
Open the Password Generator tool. -
Set Password Length to 36. -
Enable all character toggles (Lowercase, Uppercase, Digits, Special Characters). -
In the "Exclude the following characters..." field, paste: @, :, /, %, &, ?, #, +, !, $, ^, * -
Click "Generate password(s)". -
The app closes/crashes instantly.
Scenario 2: Logic Failure (Asterisk Loop)
- Use the same settings as above.
- Change the exclusion field to: ^, *
- Click "Generate password(s)".
- The output field fills with lines containing only ************************************.
Expected behavior
The app should handle excluded characters without crashing, even if the list is long.
If the exclusion list is valid, the generator should return a random string of characters that are not in the exclusion list, while still respecting the requested password length.
If an exclusion list makes it impossible to generate a password (e.g., excluding all possible characters), the app should show a validation error instead of crashing or returning a broken string.
Screenshots
Workaround
No response
Affected platforms
Windows
Affected DevToys kind
DevToys (app with GUI)
DevToys Version
Versão 1.0.14.0 | X64 | RELEASE | 3ad0ff2d | 3ad0ff2d
Relevant Assets/Logs
No response
I'd like to work on this one. Planning to reproduce it with a unit test in DevToys.Tools and fix the generator logic there.
I dug into this. The version in the report (1.0.14.0, commit 3ad0ff2d) is DevToys v1, and both behaviors trace to ExcludeCharacters in v1's PasswordGeneratorToolViewModel, which interpolates the exclusion field directly into a regex character class: Regex.Replace(from, $@"[{excluded}]", "").
- Asterisk output:
^, *becomes[^, *]— the leading^negates the class, so everything except,, space, and*is stripped from every character set. The only surviving pool is"*", which then fills the password. - Crash: the long exclusion list empties the special-characters set (
!@#$%^&*), but each "guarantee one character per enabled set" branch guards onrandomChars[0].Lengthinstead of its own set, then indexes into the empty string — unhandledIndexOutOfRangeException.
I verified the 2.0 implementation (PasswordGeneratorHelper in DevToys.Tools) against both repro scenarios: it filters with a HashSet<char> (no regex) and guards the empty-pool case, so neither symptom reproduces there.
One gap vs. the expected behavior described here: if the exclusion list removes every available character, 2.0 silently outputs nothing instead of showing a validation message. Happy to submit a PR to DevToys.Tools adding that warning plus regression tests for these scenarios, if wanted.
Fix for the 2.0 side of this is up in DevToys-app/DevToys.Tools#77 (warning when the exclusion list removes every available character). The v1 crash is a separate code path, as noted above. Happy to adjust anything if the approach doesn't fit.