tryMigrateAuthEntry static method

Future<EmailAuth?> tryMigrateAuthEntry({
  1. required String password,
  2. required EmailAuth entry,
})

Migrates an EmailAuth entry if required.

Returns the new EmailAuth object if a migration was required, null otherwise.

Implementation

static Future<EmailAuth?> tryMigrateAuthEntry({
  required String password,
  required EmailAuth entry,
}) async {
  if (!PasswordHash(entry.hash, legacySalt: EmailSecrets.legacySalt)
      .shouldUpdateHash()) {
    return null;
  }

  var newHash = await PasswordHash.argon2id(
    password,
    pepper: EmailSecrets.pepper,
    allowUnsecureRandom: AuthConfig.current.allowUnsecureRandom,
  );

  return entry.copyWith(hash: newHash);
}