changePassword static method
Updates the password of a user.
Implementation
static Future<bool> changePassword(
Session session,
int userId,
String oldPassword,
String newPassword,
) async {
var auth = await session.db.findSingleRow<EmailAuth>(
where: EmailAuth.t.userId.equals(userId),
);
if (auth == null) {
return false;
}
// Check old password
if (auth.hash != generatePasswordHash(oldPassword, auth.email)) {
return false;
}
// Update password
auth.hash = generatePasswordHash(newPassword, auth.email);
await session.db.update(auth);
return true;
}