PasswordConfig

Configures password validation rules (min length, character types), conditional enforcement, and custom error messages.

This document describes the PasswordConfig interface and related interfaces used to configure password validation.

Interfaces:

  • PasswordConfig: Defines the configuration options for password validation.
  • PasswordValidation: Specifies the actual validation rules for the password (e.g., minimum length, character requirements).
  • PasswordValidationMessage: Defines the error message text for each validation rule (optional).

PasswordConfig Interface:

Properties:

  • validation (Optional): An object of type PasswordValidation that specifies the password validation rules.
  • conditionalExpression (Optional): A string or function that determines whether to apply the password validation based on other form field values, enabling dynamic validation.
  • message (Optional): A PasswordValidationMessage object or a string representing the custom error message for failed password validation.
  • messageKey (Optional): A PasswordValidationMessage object or a string key used to lookup a custom error message from a translation resource for dynamic localization based on user language.

PasswordValidation Interface:

Properties:

  • digit (Optional): Boolean flag indicating whether to require at least one digit (0-9). alphabet (Optional): Boolean flag indicating whether to require at least one alphabetic character (a-z, A-Z).
  • contains (Optional): String specifying a custom character sequence that the password must contain.
  • lowerCase (Optional): Boolean flag indicating whether to require at least one lowercase letter (a-z).
  • upperCase (Optional): Boolean flag indicating whether to require at least one uppercase letter (A-Z).
  • specialCharacter (Optional): Boolean flag indicating whether to require at least one special character (e.g., !@#$%^&*).
  • minLength (Optional): Number representing the minimum allowed password length.
  • maxLength (Optional): Number representing the maximum allowed password length.

PasswordValidationMessage Interface:

Each property corresponds to a validation rule in PasswordValidation (e.g., digit, minLength) and holds the specific error message text displayed when that rule fails.

Using PasswordConfig:

  1. Define a PasswordValidation object specifying the desired password complexity rules (e.g., minLength: 8, upperCase: true).
  2. (Optional) Create a PasswordValidationMessage object to define custom error messages for each validation rule.
  3. Configure the PasswordConfig object:
    • Set the validation property to the created PasswordValidation object.
    • (Optional) Set the conditionalExpression for dynamic validation based on other form fields.
    • (Optional) Set the message or messageKey property to customize the overall error message.