public IActionResult Login(LoginViewModel loginViewModel) { if (ModelState.IsValid) { if (!_userRepository.CheckUserExists(loginViewModel.UserName)) { ModelState.AddModelError("", "Entered Username or Password is Invalid"); } else { var getuserdetails = _userRepository.GetUserbyUserName(loginViewModel.UserName); if (getuserdetails == null) { ModelState.AddModelError("", "Entered Username or Password is Invalid"); return(View()); } var usersalt = _userRepository.GetUserSaltbyUserid(getuserdetails.UserId); if (usersalt == null) { ModelState.AddModelError("", "Entered Username or Password is Invalid"); return(View()); } if (!_verificationRepository.CheckIsAlreadyVerifiedRegistration(getuserdetails.UserId)) { ModelState.AddModelError("", "Email Verification Pending"); return(View()); } var generatehash = GenerateHashSha512.Sha512(loginViewModel.Password, usersalt.PasswordSalt); if (string.Equals(getuserdetails.PasswordHash, generatehash, StringComparison.Ordinal)) { HttpContext.Session.SetString("UserId", Convert.ToString(getuserdetails.UserId)); HttpContext.Session.SetString("UserName", Convert.ToString(getuserdetails.Username)); return(RedirectToAction("Dashboard", "Dashboard")); } else { ModelState.AddModelError("", "Entered Username or Password is Invalid"); } return(View()); } } return(View()); }
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")); }