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));
        }
        public IActionResult Authenticate([FromBody] AuthenticateRequest authenticateRequest)
        {
            if (ModelState.IsValid)
            {
                if (!_userMasterQueries.CheckUserExists(authenticateRequest.Username))
                {
                    return(BadRequest(new BadRequestResponse("Entered Username or Password is Invalid")));
                }
                else
                {
                    var loggedInuserdetails = _userMasterQueries.GetCommonUserDetailsbyUserName(authenticateRequest.Username);

                    if (loggedInuserdetails == null)
                    {
                        return(BadRequest(new BadRequestResponse("Username or password is incorrect")));
                    }

                    var usersalt = _userTokensQueries.GetUserSaltbyUserid(loggedInuserdetails.UserId);
                    if (usersalt == null)
                    {
                        return(BadRequest(new BadRequestResponse("Entered Username or Password is Invalid")));
                    }

                    if (loggedInuserdetails.Status == false)
                    {
                        return(BadRequest(new BadRequestResponse("Your Account is InActive Contact Administrator")));
                    }

                    var generatepasswordhash = HashHelper.CreateHashSHA512(authenticateRequest.Password).ToLower();
                    var generatedhash        = HashHelper.CreateHashSHA512(generatepasswordhash, usersalt.PasswordSalt);

                    if (string.Equals(loggedInuserdetails.PasswordHash, generatedhash, StringComparison.Ordinal))
                    {
                        var response = GenerateJwtToken(loggedInuserdetails);
                        return(Ok(new OkResponse("Success", new AuthenticateResponse()
                        {
                            Token = response
                        })));
                    }
                }
            }

            return(BadRequest(new BadRequestResponse("Username or password is incorrect")));
        }
        public IActionResult Login(LoginViewModel loginViewModel)
        {
            if (ModelState.IsValid)
            {
                if (!_userMasterQueries.CheckUserExists(loginViewModel.Username))
                {
                    ModelState.AddModelError("", "Entered Username or Password is Invalid");
                }
                else
                {
                    var loggedInuserdetails = _userMasterQueries.GetCommonUserDetailsbyUserName(loginViewModel.Username);

                    if (loggedInuserdetails == null)
                    {
                        ModelState.AddModelError("", "Entered Username or Password is Invalid");
                        return(View());
                    }

                    var usersalt = _userTokensQueries.GetUserSaltbyUserid(loggedInuserdetails.UserId);
                    if (usersalt == null)
                    {
                        ModelState.AddModelError("", "Entered Username or Password is Invalid");
                        return(View());
                    }

                    if (loggedInuserdetails.RoleId == Convert.ToInt32(RolesHelper.Roles.User))
                    {
                        if (!_userMasterQueries.CheckIsAlreadyVerifiedRegistration(loggedInuserdetails.UserId))
                        {
                            ModelState.AddModelError("", "Email Verification Pending");
                            return(View());
                        }
                    }

                    if (loggedInuserdetails.Status == false)
                    {
                        ModelState.AddModelError("", "Your Account is InActive Contact Administrator");
                        return(View());
                    }

                    var generatedhash = HashHelper.CreateHashSHA512(loginViewModel.Password, usersalt.PasswordSalt);

                    if (string.Equals(loggedInuserdetails.PasswordHash, generatedhash, StringComparison.Ordinal))
                    {
                        SetAuthenticationCookie();
                        SetApplicationSession(loggedInuserdetails);

                        switch (loggedInuserdetails.RoleId)
                        {
                        case 1:
                            return(RedirectToAction("Dashboard", "Dashboard", new { Area = "Administration" }));

                        case 2:
                            return(RedirectToAction("Dashboard", "UserDashboard"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Entered Username or Password is Invalid");
                    }

                    return(View());
                }
            }

            return(View());
        }