Skip to main content
Back to Browser

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

ParameterTypeRequiredDescription
valuestringThe candidate value.
policyPasswordPolicyThe 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.

PropertyTypeDescription
keystringStable identifier for the rule.
messageKeystringi18n key describing the requirement, resolved by the caller.
paramsRecord<string, string | number>Optional substitution params for messageKey.
passedbooleanWhether value satisfies this rule.

Usage

import { evaluatePasswordPolicy } from '@thunderid/browser'

const results = evaluatePasswordPolicy('sh0rt', { regex: '^.{8,}$' })
const isValid = results.every((result) => result.passed)

Explore with AI

ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.