resetPassword static method

Future<bool> resetPassword(
  1. Session session,
  2. String verificationCode,
  3. String password
)

Resets a users password using a password reset verification code.

Implementation

static Future<bool> resetPassword(
  Session session,
  String verificationCode,
  String password,
) async {
  var passwordReset = await session.db.findSingleRow<EmailReset>(
    where: EmailReset.t.verificationCode.equals(verificationCode) &
        (EmailReset.t.expiration > DateTime.now().toUtc()),
  );

  if (passwordReset == null) return false;

  var emailAuth = await session.db.findSingleRow<EmailAuth>(
    where: EmailAuth.t.userId.equals(passwordReset.userId),
  );

  if (emailAuth == null) return false;

  emailAuth.hash = generatePasswordHash(password, emailAuth.email);
  await session.db.update(emailAuth);

  return true;
}