public IActionResult ForgotPassword([Bind("emailAddress, password")] ForgotPassword model) { if (ModelState.IsValid) { var user = db.ProfileData.Where(e => e.Email == model.emailAddress).FirstOrDefault(); if (user != null) { string token = TokenProviderService.GenerateToken(); var salt = db.AccountData.Where(e => e.ProfileId == user.Id).FirstOrDefault(); string encryptedToken = EncryptionDecryptionService.Encrypt(token, user.Email, salt.Salt); PasswordForgottenEmail.SendPasswordForgottenEmail(user, encryptedToken, configuration); TempData["Email"] = model.emailAddress; return(RedirectToAction("ForgotPasswordConfirmation", "ForgotPassword")); } else { TempData["Email"] = model.emailAddress; return(RedirectToAction("ForgotPasswordConfirmation", "ForgotPassword")); } } else { return(View()); } }
public void GenerateEncryptedString() { string unEncryptedString = "63fu6929r40w"; string email = "*****@*****.**"; string salt = "5574m5w=="; var encryptedString = EncryptionDecryptionService.Encrypt(unEncryptedString, email, salt); Assert.IsNotNull(encryptedString); }
/// <summary> /// Show password reset page /// </summary> /// <param name="email">e-mail address of useraccount for which password will be changed </param> /// <param name="token">Token that has been provided by creation of password forgotten e-mail</param> /// <returns>A redirect to the Forgotpassword page or the page in which you can reset your password</returns> public IActionResult ResetPassword([FromQuery(Name = "email")] string email, [FromQuery(Name = "token")] string token) { if (email != null || token != null) { var user = db.ProfileData.Where(e => e.Email == email).FirstOrDefault(); if (user != null) { var salt = db.AccountData.Where(e => e.ProfileId == user.Id).FirstOrDefault(); var decryptedToken = EncryptionDecryptionService.Decrypt(token, user.Email, salt.Salt); if (decryptedToken != "Invalid") { DateTime dateTime = TokenProviderService.GetDateTime(decryptedToken); if (dateTime > DateTime.UtcNow.AddHours(-1)) { TempData["Email"] = email; return(View()); } else { return(RedirectToAction("ForgotPasswordError")); } } else { return(RedirectToAction("ForgotPasswordError")); } } else { return(RedirectToAction("ForgotPasswordError")); } } else { return(RedirectToAction("ForgotPasswordError")); } }