public static async Task RecordInvalidLoginAttemptAsync(this IUserAuthRepositoryAsync repo, IUserAuth userAuth, CancellationToken token = default) { var feature = HostContext.GetPlugin <AuthFeature>(); if (feature?.MaxLoginAttempts == null) { return; } userAuth.InvalidLoginAttempts += 1; userAuth.LastLoginAttempt = userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.InvalidLoginAttempts >= feature.MaxLoginAttempts.Value) { userAuth.LockedDate = userAuth.LastLoginAttempt; } await repo.SaveUserAuthAsync(userAuth, token); }
public static async Task RecordSuccessfulLoginAsync(this IUserAuthRepositoryAsync repo, IUserAuth userAuth, bool rehashPassword, string password, CancellationToken token = default) { var recordLoginAttempts = HostContext.GetPlugin <AuthFeature>()?.MaxLoginAttempts != null; if (recordLoginAttempts) { userAuth.InvalidLoginAttempts = 0; userAuth.LastLoginAttempt = userAuth.ModifiedDate = DateTime.UtcNow; } if (rehashPassword) { userAuth.PopulatePasswordHashes(password); } if (recordLoginAttempts || rehashPassword) { await repo.SaveUserAuthAsync(userAuth, token); } }