validatePasswordHash static method

Future<bool> validatePasswordHash(
  1. String password,
  2. String email,
  3. String hash, {
  4. void onValidationFailure({
    1. required String passwordHash,
    2. required String storedHash,
    })?,
  5. void onError(
    1. Object e
    )?,
})

Generates a password hash from the password using the provided hash algorithm and validates that they match.

If the password hash does not match the provided hash, the onValidationFailure function is called with the hash and the password hash as arguments.

If an error occurs, the onError function is called with the error as argument.

Implementation

static Future<bool> validatePasswordHash(
  String password,
  String email,
  String hash, {
  void Function({required String passwordHash, required String storedHash})?
      onValidationFailure,
  void Function(Object e)? onError,
}) async {
  try {
    return await PasswordHash(
      hash,
      legacySalt: EmailSecrets.legacySalt,
      legacyEmail: AuthConfig.current.extraSaltyHash ? email : null,
      pepper: EmailSecrets.pepper,
    ).validate(password, onValidationFailure: onValidationFailure);
  } catch (e) {
    onError?.call(e);
    return false;
  }
}