Skip to main content

`evaluatePasswordPolicy()`

Cloud has the newest features. Some may not be in a release yet; the newest release is Identity & Access Management 7.3.0.

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
valuestring✅The candidate value.
policyPasswordPolicy✅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.

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)

Was this page helpful?