private async Task ValidateAttempt(PasswordReset request, ResetResult result, int maxAttempts, DateTime time, string key) { if (request.Attempts >= maxAttempts) { result.Success = false; result.Blocked = true; result.Attempts = request.Attempts; } if (request.KeyExpires < time) { result.Success = false; result.Expired = true; result.Attempts = request.Attempts; } if (Equals(request.ResetKey, key)) { request.ResetVerified = true; result.Success = true; await _dbContext.SaveChangesAsync(); } else { result.Success = false; result.Attempts = request.Attempts; request.Attempts++; } }
public ResetResult WdaForgotPassword(string Email, string remoteAddress) { ResetResult resetResult = new ResetResult(); string NewPassword = Utility.GenPassword(10); int MaxFailedPasswordResetCount; string strMaxFailedPasswordResetCount = WebConfigurationManager.AppSettings["MaxFailedPasswordResetCount"]; if (!String.IsNullOrEmpty(strMaxFailedPasswordResetCount)) { MaxFailedPasswordResetCount = Int32.Parse(strMaxFailedPasswordResetCount); } else { MaxFailedPasswordResetCount = 15; } resetResult = _storedProcedures.WdaForgotPassword(Email, NewPassword, MaxFailedPasswordResetCount, remoteAddress).First(); if (resetResult.IsPasswordReset == 1) { Utility.SendMailForPasswordReset(Email, NewPassword); } return(resetResult); }
public IHttpActionResult ForgotPassword(string Email) { ResetResult resetResult = userSvc.WdaForgotPassword(Email, HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]); if (resetResult.IsPasswordReset == 1) { return(Ok(resetResult)); } else { ModelState.AddModelError("", resetResult.Remarks); } return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.ToError()))); }
private void OnResetPasswordCommand() { if ((_newPassword == null || _confirmPassword == null) || _newPassword.Equals(_confirmPassword) == false) { this.AddError("NewPassword", "New Password Does Not Match Confirmation Password"); } else { this.RemoveError("NewPassword"); ResetResult result = _userAccountService.ChangeUserPassword(_user, _newPassword); Messenger.Default.Send <PasswordChangeSuccessMessage>(new PasswordChangeSuccessMessage(result)); Messenger.Default.Send <NavigationMessage>(new NavigationMessage("resetresult")); NewPassword = null; ConfirmPassword = null; } }
public void ChangeUserPassword_Returns_ResetResult_With_Failure_When_Entered_User_Does_Not_Exist() { BannerID testBannerID = BannerID.CreateBannerID("A00000001"); string testSamAccountName = "testSamAccount"; string newPassword = "******"; User testEnteredUser = new User(testBannerID, testSamAccountName, "test, user one"); var mockRepo = new Mock <IActiveDirectoryRepository>(); mockRepo.Setup(repo => repo.FindUserByBannerID(testEnteredUser.BannerID)).Returns((User)null); UserAccountService userAccountService = new UserAccountService(mockRepo.Object); ResetResult result = userAccountService.ChangeUserPassword(testEnteredUser, newPassword); Assert.IsTrue(result.HasErrorMessage); Assert.AreEqual(testEnteredUser, result.User); }
public void ChangeUserPassword_Returns_ResetResult_With_No_Failures() { BannerID testBannerID = BannerID.CreateBannerID("A00000000"); string testSamAccountName = "testSamAccount"; string newPassword = "******"; User testUser = new User(testBannerID, testSamAccountName, "test, user one"); var mockRepo = new Mock <IActiveDirectoryRepository>(); mockRepo.Setup(repo => repo.FindUserByBannerID(testUser.BannerID)).Returns(testUser); mockRepo.Setup(repo => repo.ChangeUserPassword(testUser, newPassword)).Returns(true); mockRepo.Setup(repo => repo.ChangeUserResetAttribute(testUser)).Returns(true); UserAccountService userAccountService = new UserAccountService(mockRepo.Object); ResetResult result = userAccountService.ChangeUserPassword(testUser, newPassword); Assert.IsFalse(result.HasErrorMessage); Assert.AreEqual(testUser, result.User); }
public void PasswordResetCommand_Calls_ChangeUserPassword_In_UserAccountService_If_Both_Password_Fields_Match() { User _testUser = new User(BannerID.CreateBannerID("A00000001"), "samAccountName", "test, user 1"); ResetResult testResult = new ResetResult(_testUser, true, null); string newPassword = "******"; string matchingPassword = "******"; var mockAccountService = new Mock <IUserAccountService>(); mockAccountService.Setup(service => service.ChangeUserPassword(It.IsAny <User>(), It.IsAny <string>())).Returns(testResult).Verifiable(); PasswordResetViewModel _viewModel = new PasswordResetViewModel(mockAccountService.Object) { NewPassword = newPassword, ConfirmPassword = matchingPassword }; _viewModel.ResetPasswordCommand.Execute(null); Mock.Verify(mockAccountService); }
protected void UpdateShouldResetText() { ResetResult shouldReset = resetOrNotCalculator.ShouldReset(); string resultText = ""; Color color = State.LayoutSettings.TextColor; switch (shouldReset.ResetAction) { case ResetAction.RUN_NOT_STARTED: resultText = "Run not started"; break; case ResetAction.CONTINUE_RUN: resultText = "Continue the run"; color = State.LayoutSettings.AheadGainingTimeColor; TimeSpan timeBeforeReset = shouldReset.TimeBeforeReset; // display the time is less than a minute is left before the reset if (timeBeforeReset < TimeSpan.FromMinutes(1)) { resultText += $" (-{timeBeforeReset.Seconds}.{timeBeforeReset.Milliseconds / 100})"; } break; case ResetAction.RESET: resultText = "Reset"; color = State.LayoutSettings.BehindLosingTimeColor; break; case ResetAction.CALCULATING: resultText = "Calculating..."; break; case ResetAction.NOT_APPLICABLE: resultText = "N/A"; break; } InternalComponent.InformationValue = resultText; InternalComponent.ValueLabel.ForeColor = color; }
public void Failed_Reset_Sends_PasswordChangeSuccessMessage_With_False() { User _testUser = new User(BannerID.CreateBannerID("A00000001"), "samAccountName", "test, user 1"); ResetResult testResult = new ResetResult(_testUser, false, "failure"); var mockAccountService = new Mock <IUserAccountService>(); mockAccountService.Setup(service => service.ChangeUserPassword(It.IsAny <User>(), It.IsAny <string>())).Returns(testResult); PasswordResetViewModel _viewModel = new PasswordResetViewModel(mockAccountService.Object); string newPassword = "******"; string matchingPassword = "******"; _viewModel.NewPassword = newPassword; _viewModel.ConfirmPassword = matchingPassword; PasswordChangeSuccessMessage passwordChangeSuccessMessage = null; Messenger.Default.Register <PasswordChangeSuccessMessage>(this, msg => passwordChangeSuccessMessage = msg); _viewModel.ResetPasswordCommand.Execute(null); Assert.IsNotNull(passwordChangeSuccessMessage); Assert.IsFalse(passwordChangeSuccessMessage.ResetResult.PasswordChanged); }
public async Task <ResetResult> ValidateRequestAsync(string userId, string key) { var request = await ReadResetDataAsync(userId); if (request == null) { return(new ResetResult() { Success = false, NoRequest = true, }); } var maxAttempts = Convert.ToInt32(_configuration["PasswordReset:MaxAttempts"]); var time = DateTime.Now; var output = new ResetResult(); await ValidateAttempt(request, output, maxAttempts, time, key); await _dbContext.SaveChangesAsync(); return(output); }
public PasswordChangeSuccessMessage(ResetResult result) { ResetResult = result; }