checkNewPassword method

Future<void> checkNewPassword(
  1. String password
)

Throws DVBreachedPasswordRefusal for a password in the breach corpus. Call it on every password change as well as sign-up.

Implementation

Future<void> checkNewPassword(String password) async {
  final breached = breachedPasswords;
  if (breached == null) return;

  final bool found;
  try {
    found = await breached.contains(password);
  } catch (error) {
    final unavailable = error is DVBreachedPasswordsUnavailable
        ? error
        : DVBreachedPasswordsUnavailable(error);
    if (breachCheckFailsClosed) throw unavailable;
    DVObservability.log(
      'The breached-password check could not be made; the password was '
      'accepted unchecked.',
      level: DVLogLevel.warn,
      error: unavailable.cause,
    );
    return;
  }
  if (found) {
    const refusal = DVBreachedPasswordRefusal();
    DVObservability.log(refusal.message,
        level: DVLogLevel.warn, code: refusal.code);
    throw refusal;
  }
}