checkPassword static method

double checkPassword(
  1. String password
)

check password strong and return double value 0-1. original source code is here

Implementation

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

  final 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]
  double logistic(double x) => 1.0 / (1.0 + exp(-x));

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

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