verifyPassword method

bool verifyPassword(
  1. String password,
  2. String hash,
  3. String salt,
  4. int iterations,
  5. int keyLength,
)

Verify a password against a stored hash

password is the plain text password to verify hash is the stored hash to compare against salt is the salt used for the hash iterations is the number of iterations used keyLength is the length of the derived key

Returns true if the password matches, false otherwise

Implementation

bool verifyPassword(
  String password,
  String hash,
  String salt,
  int iterations,
  int keyLength,
) {
  final computedHash = _pbkdf2(
    password.codeUnits,
    base64.decode(salt),
    iterations,
    keyLength,
  );

  return _constantTimeEquals(
    base64.decode(hash),
    computedHash,
  );
}