public IActionResult Process(ChangePasswordViewModel changePasswordViewModel) { if (ModelState.IsValid) { var userid = Convert.ToString(HttpContext.Session.GetString("UserId")); var getuserdetails = _userRepository.GetUserbyUserId(Convert.ToInt64(userid)); var usersalt = _userRepository.GetUserSaltbyUserid(getuserdetails.UserId); var generatehash = GenerateHashSha512.Sha512(changePasswordViewModel.CurrentPassword, usersalt.PasswordSalt); if (changePasswordViewModel.CurrentPassword == changePasswordViewModel.Password) { ModelState.AddModelError("", @"New Password Cannot be same as Old Password"); return(View(changePasswordViewModel)); } if (!string.Equals(getuserdetails.PasswordHash, generatehash, StringComparison.Ordinal)) { ModelState.AddModelError("", "Current Password Entered is InValid"); return(View(changePasswordViewModel)); } if (!string.Equals(changePasswordViewModel.Password, changePasswordViewModel.ConfirmPassword, StringComparison.Ordinal)) { TempData["Reset_Error_Message"] = "Password Does not Match"; return(View(changePasswordViewModel)); } else { var salt = GenerateRandomNumbers.RandomNumbers(20); var saltedpassword = GenerateHashSha512.Sha512(changePasswordViewModel.Password, salt); var result = _userRepository.UpdatePasswordandHistory(getuserdetails.UserId, saltedpassword, salt, "C"); if (result > 0) { // TempData["ChangePassword_Success_Message"] = "Password Changed Successfully"; var updateresult = _verificationRepository.UpdateRegisterVerification(getuserdetails.UserId); return(RedirectToAction("Process", "ChangePassword")); } else { TempData["Reset_Error_Message"] = "Something Went Wrong Please try again!"; return(View(changePasswordViewModel)); } } } return(View(changePasswordViewModel)); }
public IActionResult Verify(string key, string hashtoken) { try { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(hashtoken)) { var arrayVakue = SecurityManager.SplitToken(key); if (arrayVakue != null) { // arrayVakue[1] "UserId" var rvModel = _verificationRepository.GetRegistrationGeneratedToken(arrayVakue[1]); if (rvModel != null) { var result = SecurityManager.IsTokenValid(arrayVakue, hashtoken, rvModel.GeneratedToken); if (result == 1) { TempData["TokenErrorMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 2) { TempData["TokenErrorMessage"] = "Sorry Verification Link Expired Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } if (result == 0) { if (_verificationRepository.CheckIsAlreadyVerifiedRegistration(Convert.ToInt64(arrayVakue[1]))) { TempData["TokenErrorMessage"] = "Sorry Link Expired"; return(RedirectToAction("Login", "Portal")); } HttpContext.Session.SetString("VerificationUserId", arrayVakue[1]); var updateresult = _verificationRepository.UpdateRegisterVerification(Convert.ToInt64(arrayVakue[1])); if (updateresult) { TempData["Verify"] = "Done"; return(RedirectToAction("Completed", "VerifyRegistration")); } else { TempData["TokenErrorMessage"] = "Sorry Verification Failed Please request a new Verification link!"; return(RedirectToAction("Login", "Portal")); } } } } } } 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")); }