validate method

String? validate(
  1. String password
)

Validates the password based on the configured rules.

Implementation

String? validate(String password) {
  if (password.length < minLength) {
    return 'Password must be at least $minLength characters long';
  }
  if (requireDigit && !RegExp(r'\d').hasMatch(password)) {
    return 'Password must contain at least one digit';
  }
  if (requireUppercase && !RegExp(r'[A-Z]').hasMatch(password)) {
    return 'Password must contain at least one uppercase letter';
  }
  if (requireLowercase && !RegExp(r'[a-z]').hasMatch(password)) {
    return 'Password must contain at least one lowercase letter';
  }
  if (requireSymbol &&
      !RegExp(r'[!@#$%^&*(),.?":{}|<>]').hasMatch(password)) {
    return 'Password must contain at least one symbol';
  }
  return null;
}