password static method

bool password(
  1. String password
)

Check if a string is a valid password password.

Implementation

static bool password(String password) {
  // Check minimum length
  if (password.length < 8) {
    return false;
  }

  // Check for at least one uppercase, one lowercase, one number, and one special character
  RegExp upperCase = RegExp(r'[A-Z]');
  RegExp lowerCase = RegExp(r'[a-z]');
  RegExp digit = RegExp(r'[0-9]');
  RegExp specialChar = RegExp(r'[!@#$%^&*(),.?":{}|<>]');

  if (!upperCase.hasMatch(password) ||
      !lowerCase.hasMatch(password) ||
      !digit.hasMatch(password) ||
      !specialChar.hasMatch(password)) {
    return false;
  }

  return true;
}