computePasswordSecurityLevel static method

int computePasswordSecurityLevel(
  1. String password
)

0 low; 1 medium; 2 high

Implementation

static int computePasswordSecurityLevel(String password) {
  if (password.length < 6) {
    return 0;
  }

  bool hasUppercase = password.contains(RegExp(r'[A-Z]'));
  bool hasLowercase = password.contains(RegExp(r'[a-z]'));
  bool hasEnglish = hasUppercase || hasLowercase;
  bool hasDigits = password.contains(RegExp(r'[0-9]'));
  bool hasSpecialCharacters =
      password.contains(RegExp(r'[!@#$%^&*(),.?":{}|<>]'));

  if (hasEnglish && hasDigits && hasSpecialCharacters) {
    return 2;
  } else if ((hasEnglish && hasDigits) ||
      (hasEnglish && hasSpecialCharacters) ||
      (hasDigits && hasSpecialCharacters)) {
    return 1;
  } else {
    return 0;
  }
}