public async Task <ActionResult> ResetPassword(string password, string confirmPassword, string payload) { if (password != confirmPassword) { ViewData["error"] = "Detta lösenord stämmer inte överens med det första du angav."; } if (!_userManager.IsUserPasswordValid(password)) { ViewData["error"] = "Lösenordet är inte av rätt typ. Se krav för nytt lösenord."; } if (ViewData["error"] != null) { ViewData["payload"] = payload; return(PageView("Reset password")); } payload = payload?.Replace(' ', '+'); try { var data = _tokenGenerator.Decrypt <ResetPasswordConfirmationData>(payload); //check if the guid is still valid var checkGuidResult = await _securityRepo.CheckPasswordGuidAsync(data.UserName, data.GuidString); if (!checkGuidResult) { return(new HttpStatusCodeResult(400)); } //activate user await _userManager.ActivateAccount(data.UserName); //reset now await _securityRepo.ChangePasswordAsync(data.UserName, password); } //pretend these security error didn't happen catch (CryptographicException) { } catch (ArgumentException) { } catch (FaultException ex) when(ex.Message.Contains("The new password cannot be the same")) { ViewData["error"] = "Lösenordet är inte av rätt typ. Se krav för nytt lösenord."; return(PageView("Reset password")); } // return success anyway return(View("~/Views/Login/ResetPasswordSuccessful.cshtml", StartPageViewModel)); }
public CustomerBasicInfo GetInternalCustomerNumber(HttpContextBase httpContext) { if (httpContext.Request.Cookies.AllKeys?.Contains(Cookies.InternalActiveCustomer) != true) { return(null); } var cookieValue = httpContext.Request.Cookies[Cookies.InternalActiveCustomer]; try { var customer = _tokenGenerator.Decrypt <CustomerBasicInfo>(cookieValue?.Value); return(customer); } catch (Exception ex) when(ex is CryptographicException || ex is ArgumentException) { return(null); } }