public IActionResult Verify(string key, string hashtoken) { try { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(hashtoken)) { var arrayVakue = SecurityTokenHelper.SplitToken(key); if (arrayVakue != null) { // arrayVakue[1] "UserId" var userId = Convert.ToInt64(arrayVakue[1]); var rvModel = _verificationQueries.GetResetGeneratedToken(userId); if (rvModel != null) { var result = SecurityTokenHelper.IsTokenValid(arrayVakue, hashtoken, rvModel.GeneratedToken); if (result == 1) { TempData["TokenMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 2) { TempData["TokenMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 0) { HttpContext.Session.SetString("VerificationUserId", arrayVakue[1]); HttpContext.Session.SetString("ActiveVerification", "1"); return(RedirectToAction("Reset", "ResetPassword")); } } } } } catch (Exception) { TempData["TokenMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } TempData["TokenMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); }
public IActionResult Reset(ResetPasswordViewModel resetPasswordViewModel) { if (ModelState.IsValid) { var userid = Convert.ToString(HttpContext.Session.GetString("VerificationUserId")); var getuserdetails = _userMasterQueries.GetUserDetailsbyUserId(Convert.ToInt64(userid)); if (!string.Equals(resetPasswordViewModel.Password, resetPasswordViewModel.ConfirmPassword, StringComparison.Ordinal)) { TempData["Reset_Error_Message"] = "Password Does not Match"; return(View(resetPasswordViewModel)); } else { var salt = GenerateRandomNumbers.GenerateRandomDigitCode(20); var saltedpassword = HashHelper.CreateHashSHA512(resetPasswordViewModel.Password, salt); _unitOfWorkEntityFramework.UserMasterCommand.UpdatePasswordandHistory(getuserdetails.UserId, saltedpassword, salt, "R"); var result = _unitOfWorkEntityFramework.Commit(); if (result) { var resetPasswordVerificationobj = _verificationQueries.GetResetGeneratedToken(getuserdetails.UserId); _unitOfWorkEntityFramework.VerificationCommand.UpdateResetVerification(resetPasswordVerificationobj); var updateresult = _unitOfWorkEntityFramework.Commit(); if (updateresult) { TempData["Reset_Success_Message"] = "Password Reset Successfully!"; } return(RedirectToAction("Login", "Portal")); } else { TempData["Reset_Error_Message"] = "Something Went Wrong Please try again!"; return(View(resetPasswordViewModel)); } } } return(View(resetPasswordViewModel)); }