public async Task <ResponseResult> UnLockAccount(long userId) { // check if userId exists var user = await userBusiness.Get(userId); if (user == null) { return(new ResponseResult { Success = false, Messages = new[] { ErrorMessage_UserDoesNotExist } }); } await authenticateAttemptBusiness.ResetRemainingAttempts(userId); return(await data.UnLockAccount(userId)); }
public async Task <AuthenticateAttempResult> Check(long userId, string hash, string password) { var checkResult = passwordHasher.Check(hash, password); if (checkResult.Verified) { var checkUserResponse = await lockAccountBusiness.CheckUser(userId); if (!checkUserResponse.Success) // account is locked { return(new AuthenticateAttempResult { Verified = false, UnverifiedAttempt = new AuthenticationToken { islocked = true, message = WarningMessage_AccountIsLocked } }); } await authenticateAttemptBusiness.ResetRemainingAttempts(userId); return(new AuthenticateAttempResult { Verified = true }); } else { await authenticateAttemptBusiness.DecreaseRemainingAttempts(userId); var remainingAttempts = await authenticateAttemptBusiness.GetRemainingAttemptCount(userId); if (remainingAttempts < 0) // lock the account { await lockAccountBusiness.LockAccount(userId); return(new AuthenticateAttempResult { Verified = false, UnverifiedAttempt = new AuthenticationToken { islocked = true, message = WarningMessage_AccountIsLocked, remainingattempts = remainingAttempts } }); } return(new AuthenticateAttempResult { Verified = false, UnverifiedAttempt = new AuthenticationToken { message = WarningMessage_AuthenticateFailed, islocked = false, remainingattempts = remainingAttempts } }); } }