checkPassword method

double checkPassword({
  1. required String password,
})

check password strong and retrun double value 0-1 input string password

Implementation

double checkPassword({required String password}) {
  /// if [password] is empty return 0.0
  if (password.isEmpty) return 0.0;

  double bonus;
  if (RegExp(r'^[a-z]*$').hasMatch(password)) {
    bonus = 1.0;
  } else if (RegExp(r'^[a-z0-9]*$').hasMatch(password)) {
    bonus = 1.2;
  } else if (RegExp(r'^[a-zA-Z]*$').hasMatch(password)) {
    bonus = 1.3;
  } else if (RegExp(r'^[a-z\-_!?]*$').hasMatch(password)) {
    bonus = 1.3;
  } else if (RegExp(r'^[a-zA-Z0-9]*$').hasMatch(password)) {
    bonus = 1.5;
  } else {
    bonus = 1.8;
  }

  /// return double value [0-1]
  final logistic = (double x) {
    return 1.0 / (1.0 + exp(-x));
  };

  /// return double value [0-1]
  final curve = (double x) {
    return logistic((x / 3.0) - 4.0);
  };

  /// return double value [0-1]
  return curve(password.length * bonus);
}