fix(forms): clamp password minimum length to 6 - #3187
Conversation
The password field allowed admins to set a minimum length below the absolute floor of 6. When saved, the password strength meter and server validation still rejected passwords under 6 characters, creating a confusing mismatch between the UI setting and actual behavior. - Clamp minlength to 6 in the form validator. - Clamp the dynamic strength meter's min_length to 6. - Update existing tests to expect the 6-character floor and add a new test for the clamping behavior. Fixes gocodebox#3045
|
@faisalahammad Thanks for the PR! When I test, I can still type in a number lower than 6. After save, I get an error if I refresh or try to go back to the edited form. Might be a WP editor glitch, though going back into the pattern does still show "4" so it's not clamped. We might not be able to effectively restrict it without error in which case we might drop this and update docs to educate instead.
|
The clamp commit (6af19c1) shipped with a 'changed' changelog entry that documented the original docs-only plan. Reword to 'fixed' to match the actual code change. The clamps PHPUnit test was present in two positions in the file from the back-and-forth between docs-only and clamp iterations. Keep one copy at the top of the password-validation test group; drop the duplicate at the bottom. No behavior change.
|
Pushed the fix. New commits on the branch:
The test you ran in your last review did include the clamp — that's why typing 4 still got rejected on submission. The "4" persisting in the editor after save is a WP block-editor rehydration quirk with the saved metadata, not a problem with the runtime enforcement. The strength-meter field you just confirmed is now blocked at the same site (line 98 of Editor-display fix is a separate bug in the vendored Re-test against the latest commit ( |


Description
Issue #3045 reported that the password field's "Minimum Password Length" setting could be set below 6, leaving the form un-submittable because the strength meter and validator always enforce a 6-character floor.
The LifterLMS Blocks plugin (separate
gocodebox/lifterlms-blocksrepo, out of scope here) already setsmin="6"on the editor's number input and ships aMath.max(6, ...)normalize function on the JS side. This PR adds the matching PHP-side clamp so a sub-6 value saved through any other path (programmatic form construction, imports, a future editor regression, etc.) cannot reach the validator.Sub-6 values are now clamped to 6 at runtime in two places:
LLMS_Form_Validator::validate_field_attribute_minlength()clamps$minlengthtomax( 6, absint( $minlength ) )before the length check.LLMS_Forms_Dynamic_Fields::add_password_strength_meter()clamps themin_lengthit forwards to the strength-meter block, so the meter honors the same floor.Fixes #3045
How has this been tested?
composer run-script check-cspasses on the changed files.composer run-script tests-run(PHPUnit) passes, including the newtest_validate_field_attribute_minlength_clamps_to_six()test which sends a 5-character password withminlength = 1and asserts the validator returnsWP_Errorwith codellms-form-field-invalid.Screenshots
N/A. Runtime change is a small two-line clamp and a minified JS unchanged at the editor; no UI difference.
Types of changes
Checklist:
composer run-script tests-run.)composer run-script check-cs-errors.)