Skip to content

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

Draft
tbialcz wants to merge 1 commit into
6.0from
IBX-11959-expose-password-requirements
Draft

IBX-11959: Exposed configured password requirements to the frontend#132
tbialcz wants to merge 1 commit 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 part of showing password requirements on the "Set new password" screen:

  • ibexa_password_requirements() Twig function returning the list of rules enabled in the user content type's PasswordValueValidator config (PasswordRequirementsResolver),
  • password constraint violations now carry code = requirement identifier, so the frontend can mark which rules were not met after submit,
  • PasswordResetController passes content_type to the view (the user on the reset screen is not logged in).

Validation logic itself is unchanged.

For frontend:

{# reset password page — content_type comes from the view #}
{% for requirement in ibexa_password_requirements(content_type) %}
    <li data-requirement="{{ requirement.identifier }}">
        {{ requirement.translationKey|trans(requirement.parameters, 'ibexa_password_requirements') }}
    </li>
{% endfor %}

{# pages with a logged-in user — no argument needed #}
{% for requirement in ibexa_password_requirements() %}

After submit, failed rules are in form.new_password.first.vars.errors — match error.cause.code against requirement.identifier.

For QA:

Full scenario (requirements list on the page) is testable once the storefront PR consuming this API is up. On this PR alone:

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

@sonarqubecloud

Copy link
Copy Markdown

Comment thread src/bundle/Twig/UserRuntime.php
Comment thread src/contracts/Password/PasswordRequirement.php
Comment thread src/contracts/Password/PasswordRequirementsResolverInterface.php
Comment thread src/lib/Password/PasswordRequirementsResolver.php

$minLength = (int)($constraints['minLength'] ?? 0);
if ($minLength > 0) {
$requirements[] = new PasswordRequirement(PasswordRequirement::MIN_LENGTH, ['%length%' => $minLength]);

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.

Aren't those configurable and should be dynamically incorporated? How about dynamic labels generation for custom ones?

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.

it seems they are dynamically added based on actual constraints value?

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.

the values come from the config, and only the list of rules is fixed, just like in the core schema. After the Slack discussion, I simplified it to a single rules table, and the labels and translations are generated from that table.

* and {@see \Ibexa\Core\Repository\User\PasswordValidator}.
*/
private const array REQUIREMENT_CODE_MAP = [
'User password must be at least %length% characters long' => PasswordRequirement::MIN_LENGTH,

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.

Should this be even static?

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.

it is a const . The map never changes at runtime, so const is the right i think,static would allow mutation for no reason.

@tbialcz
tbialcz marked this pull request as draft July 31, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants