evaluatePasswordPolicy()
evaluatePasswordPolicy evaluates a candidate value against a policy, returning one result when policy.regex is set, or an empty list when it isn't. An uncompilable regex is treated as passing rather than blocking the user, since the server is authoritative.
Signature
evaluatePasswordPolicy(value: string, policy: PasswordPolicy): PasswordRuleResult[]
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
value | string | ✅ | The candidate value. |
policy | PasswordPolicy | ✅ | The rule to apply, e.g. { regex: '^.{8,}$' }. See resolveChangeCredentialPolicy() for deriving one from the user type schema. |
Returns
PasswordRuleResult[]: a single-item list when policy.regex is set, otherwise an empty list.
| Property | Type | Description |
|---|---|---|
key | string | Stable identifier for the rule. |
messageKey | string | i18n key describing the requirement, resolved by the caller. |
params | Record<string, string | number> | Optional substitution params for messageKey. |
passed | boolean | Whether value satisfies this rule. |
Usage
import { evaluatePasswordPolicy } from '@thunderid/browser'
const results = evaluatePasswordPolicy('sh0rt', { regex: '^.{8,}$' })
const isValid = results.every((result) => result.passed)
Related
evaluateChangePasswordForm(): Evaluate a full new-value + confirmation form in one callresolveChangeCredentialPolicy(): Derive the policy to pass here from the user type schema