checkPasswordStrength method

PasswordStrength checkPasswordStrength()

Implementation

PasswordStrength checkPasswordStrength() {
  // 低强度:只包含字母或数字
  final lowRegex = RegExp(r'^[a-zA-Z]+$|^\d+$');

  // 中强度:包含字母和数字的组合
  final mediumRegex = RegExp(r'^(?=.*[a-zA-Z])(?=.*\d).+$');

  // 高强度:包含字母、数字和特殊字符的组合,且长度至少为8
  final highRegex = RegExp(r'^(?=.*[a-zA-Z])(?=.*\d)(?=.*[!@#$%^&*(),.?":{}|<>]).{8,}$');
  var password = this ?? '';
  if (highRegex.hasMatch(password)) {
    return PasswordStrength.high;
  } else if (mediumRegex.hasMatch(password)) {
    return PasswordStrength.medium;
  } else if (lowRegex.hasMatch(password)) {
    return PasswordStrength.low;
  } else {
    // 如果不匹配任何模式,我们也将其视为低强度
    return PasswordStrength.low;
  }
}