Skip to content

IBX-11959: Exposed configured password requirements to the frontend - #132

Open
tbialcz wants to merge 3 commits into
6.0from
IBX-11959-expose-password-requirements
Open

IBX-11959: Exposed configured password requirements to the frontend#132
tbialcz wants to merge 3 commits into
6.0from
IBX-11959-expose-password-requirements

Conversation

@tbialcz

@tbialcz tbialcz commented Jul 31, 2026

Copy link
Copy Markdown
Contributor
🎫 Issue IBX-11959

Related PRs:

Description:

Backend for showing password requirements on the "Set new password" screen:

  • ibexa_password_requirements() Twig function — returns the rules enabled in the user content type's password validator config,
  • password violations now carry code = requirement identifier, so the frontend can mark unmet rules after submit,
  • PasswordResetController passes content_type to the view (user is not logged in there).

Validation logic is unchanged.

For frontend:

{% for requirement in ibexa_password_requirements(content_type) %}
    <li data-requirement="{{ requirement.identifier }}">
        {{ requirement.translationKey|trans(requirement.parameters, 'ibexa_password_requirements') }}
    </li>
{% endfor %}

On pages with a logged-in user call it without arguments. After submit, failed rules are in form.new_password.first.vars.errors — match error.cause.code against requirement.identifier.

For QA:

  1. Reset password page: submit a password violating several rules (e.g. abc) — one error per unmet rule, password not changed.
  2. Submit a valid password — reset works as before.

Requirements list on the page will be QA-able with the storefront PR.

Comment thread src/bundle/Twig/UserRuntime.php Outdated
Comment thread src/lib/Password/PasswordRequirement.php
Comment thread src/contracts/Password/PasswordRequirementsResolverInterface.php Outdated
Comment thread src/lib/Password/PasswordRequirementsResolver.php Outdated
Comment thread src/lib/Password/PasswordRequirementsResolver.php Outdated
Comment thread src/lib/Validator/Constraints/PasswordValidator.php
@tbialcz
tbialcz marked this pull request as draft July 31, 2026 12:56
@tbialcz
tbialcz requested a review from konradoboza August 3, 2026 05:19
Comment thread tests/bundle/Twig/UserRuntimeTest.php
Comment thread tests/bundle/Twig/UserRuntimeTest.php
Comment thread tests/lib/Password/PasswordRequirementsResolverTest.php
Comment thread src/lib/Validator/Constraints/PasswordValidator.php
@tbialcz
tbialcz force-pushed the IBX-11959-expose-password-requirements branch from b5738e0 to 94174f7 Compare August 3, 2026 10:08
@tbialcz
tbialcz marked this pull request as ready for review August 3, 2026 10:09
@tbialcz
tbialcz requested a review from konradoboza August 3, 2026 10:09

@konradoboza konradoboza left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it would be nice to wire the ibexa/core PR to make sure the CI lits green.

@tbialcz
tbialcz force-pushed the IBX-11959-expose-password-requirements branch from 94174f7 to 2e387f3 Compare August 3, 2026 11:21
private function isEnabled(string $constraintKey, array $constraints, array $fieldSettings): bool
{
return match ($constraintKey) {
'minLength' => (int)($constraints['minLength'] ?? 0) > 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to use const defined before here?
PasswordRequirement::MIN_LENGTH?

@tbialcz tbialcz Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it a different thing? the match checks core's config keys (minLength) and PasswordRequirement::MIN_LENGTH is the frontend identifier (min_length)

@tbialcz
tbialcz requested a review from ViniTou August 4, 2026 07:34
// A configured password TTL implies this rule, {@see \Ibexa\Core\FieldType\User\Type::isNewPasswordRequired()}
'requireNewPassword' => !empty($constraints['requireNewPassword'])
|| (int)($fieldSettings[UserType::PASSWORD_TTL_SETTING] ?? 0) > 0,
default => !empty($constraints[$constraintKey]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to make more strict check here, 0 is actually empty and it may interfere. Shouldn't it be !isset() instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i used !empty() because it behaves the same way as the core code. If requireNewPassword is false, the rule should be disabled. If we use isset(), requireNewPassword: false would still be treated as enabled, which would be incorrect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was, it works now, but if there is a new password rule like minSpecialChars = 0 it would be incorrectly resolved as not enabled. If it's ported directly from core then it's fine, but imo it could be reiterated on this step

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it follows the current core behavior, but a rule like minSpecialChars = 0 would need its own match case anyway. I’ll add a comment to make that clear

Comment thread src/lib/Password/PasswordRequirementsResolver.php Outdated
Comment thread tests/lib/Validator/Constraint/PasswordValidatorTest.php
@tbialcz
tbialcz requested a review from barw4 August 5, 2026 06:46
@tbialcz
tbialcz force-pushed the IBX-11959-expose-password-requirements branch from 66311b9 to ec2b2c1 Compare August 5, 2026 07:57
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants