Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
 public static Task DeleteUserAuthAsync(this IUserAuthRepositoryAsync authRepo, int userAuthId, CancellationToken token = default)
 {
     return(authRepo.DeleteUserAuthAsync(userAuthId.ToString(CultureInfo.InvariantCulture), token));
 }
Exemplo n.º 4
0
 public static async Task RecordSuccessfulLoginAsync(this IUserAuthRepositoryAsync repo, IUserAuth userAuth, CancellationToken token = default)
 {
     await repo.RecordSuccessfulLoginAsync(userAuth, rehashPassword : false, password : null, token : token);
 }
 public static Task <IUserAuth> UpdateUserAuthAsync(this IUserAuthRepositoryAsync authRepo, IUserAuth existingUser, IUserAuth newUser, CancellationToken token = default) =>
 authRepo.AssertUserAuthRepositoryAsync().UpdateUserAuthAsync(existingUser, newUser, token);