コード例 #1
0
        public IActionResult Changepassword(ChangePasswordViewModel changePasswordViewModel)
        {
            if (ModelState.IsValid)
            {
                var userid         = Convert.ToString(HttpContext.Session.GetString(AllSessionKeys.UserId));
                var getuserdetails = _userMasterQueries.GetUserDetailsbyUserId(Convert.ToInt64(userid));
                var usersalt       = _userTokensQueries.GetUserSaltbyUserid(getuserdetails.UserId);
                var generatehash   = HashHelper.CreateHashSHA512(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))
                {
                    _notificationService.DangerNotification("Message", "Password Does not Match!");
                    return(View(changePasswordViewModel));
                }
                else
                {
                    var salt           = GenerateRandomNumbers.GenerateRandomDigitCode(20);
                    var saltedpassword = HashHelper.CreateHashSHA512(changePasswordViewModel.Password, salt);
                    _unitOfWorkEntityFramework.UserMasterCommand.UpdatePasswordandHistory(getuserdetails.UserId, saltedpassword, salt, "C");
                    var result = _unitOfWorkEntityFramework.Commit();

                    if (result)
                    {
                        _notificationService.SuccessNotification("Message", "Your Password Changed Successfully!");
                        var registerVerificationobj = _verificationQueries.GetRegistrationGeneratedToken(getuserdetails.UserId);
                        _unitOfWorkEntityFramework.VerificationCommand.UpdateRegisterVerification(registerVerificationobj);
                        return(RedirectToAction("Changepassword", "UserDashboard"));
                    }
                    else
                    {
                        _notificationService.DangerNotification("Message", "Something Went Wrong Please try again!");
                        return(View(changePasswordViewModel));
                    }
                }
            }

            return(View(changePasswordViewModel));
        }
コード例 #2
0
        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.GetRegistrationGeneratedToken(userId);
                        if (rvModel != null)
                        {
                            var result = SecurityTokenHelper.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 (_verificationQueries.CheckIsAlreadyVerifiedRegistration(Convert.ToInt64(arrayVakue[1])))
                                {
                                    TempData["TokenErrorMessage"] = "Sorry Link Expired";
                                    return(RedirectToAction("Login", "Portal"));
                                }

                                HttpContext.Session.SetString("VerificationUserId", arrayVakue[1]);

                                var resetPasswordVerificationobj = _verificationQueries.GetRegistrationGeneratedToken(userId);
                                _unitOfWorkEntityFramework.VerificationCommand.UpdateRegisterVerification(resetPasswordVerificationobj);
                                var updateresult = _unitOfWorkEntityFramework.Commit();

                                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"));
        }