Password constructor

Password(
  1. String? str
)

Returns a valid Password object.

Throws ValueException:

Implementation

factory Password(String? str) {
  if (str == null || str.isEmpty) {
    throw const RequiredValueException();
  } else if (str.length < minChar) {
    throw TooShortValueException(str);
  } else if (str.length > maxChar) {
    throw TooLongValueException(str);
  } else if (Password.mustContainLowerChar && !hasLowerChar(str)) {
    throw InvalidValueException(
      str,
      code: 'must-contain-lower',
      message: 'Password must contain a lower case letter.',
    );
  } else if (Password.mustContainUpperChar && !hasUpperChar(str)) {
    throw InvalidValueException(
      str,
      code: 'must-contain-upper',
      message: 'Password must contain an upper case letter.',
    );
  } else if (Password.mustContainNumeric && !hasNumeric(str)) {
    throw InvalidValueException(
      str,
      code: 'must-contain-number',
      message: 'Password must contain a number.',
    );
  } else if (Password.mustContainSpecialChar && !hasSpecialChar(str)) {
    throw InvalidValueException(
      str,
      code: 'must-have-special',
      message: 'Password must contain a special character.',
    );
  }

  return Password._(str);
}