Exemple #1
0
        public IActionResult ChangePassword(ChangePasswordViewModels model)
        {
            if (ModelState.IsValid)
            {
                var result = _accountClient.SignIn(new SignInViewModel()
                {
                    UserId   = HttpContext.User.Identity.Name,
                    Password = model.OldPassword
                });

                if (result.Succeed)
                {
                    User user = new User
                    {
                        UserId   = HttpContext.User.Identity.Name,
                        Password = model.NewPassword
                    };
                    _accountClient.UpdateProfile(user);

                    ViewBag.Message = "Change password successful";
                }
                ModelState.AddModelError(string.Empty, result.ErrorMessage);
            }
            return(View(model));
        }
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModels model)
        {
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(User);

                if (user == null)
                {
                    return(RedirectToAction("LogIn", "Account"));
                }

                var password = await userManager.ChangePasswordAsync(user, model.CurrentPassword, model.ConfirmPassword);

                if (!password.Succeeded)
                {
                    foreach (var errors in password.Errors)
                    {
                        ModelState.AddModelError(string.Empty, errors.Description);
                    }
                    return(View());
                }
                await signInManager.RefreshSignInAsync(user);

                return(View("ConfirmationChangePassword"));
            }
            return(View(model));
        }
Exemple #3
0
 public ActionResult ChangePassword(ChangePasswordViewModels changePasswordViewModels)
 {
     if (ModelState.IsValid)
     {
         if (changePasswordViewModels.NewPassword == changePasswordViewModels.OldPassword)
         {
             ModelState.AddModelError("NewPassword", "The new password must be different from old password");
             return(View(changePasswordViewModels));
         }
         var acc = _context.Accounts.SingleOrDefault(s => s.ID == changePasswordViewModels.ID);
         if (acc != null)
         {
             string pwd = AccountModels.Encrypt(changePasswordViewModels.OldPassword, true);
             if (pwd == acc.PasswordHash)
             {
                 acc.PasswordHash = AccountModels.Encrypt(changePasswordViewModels.NewPassword, true);
                 if (new AccountModels().UpdatePassword(acc))
                 {
                     ViewBag.ChangPass = true;
                 }
             }
             else
             {
                 ModelState.AddModelError("OldPassword", "Old Password is not correct.");
             }
         }
     }
     return(View(changePasswordViewModels));
 }
Exemple #4
0
        public HttpStatusCode ChangePassword(ChangePasswordViewModels changePasswordViewModels)
        {
            var           httpClient = new HttpClient();
            StringContent content    = new StringContent(JsonConvert.SerializeObject(changePasswordViewModels), Encoding.UTF8, "application/json");
            var           result     = httpClient.PutAsync("https://localhost:44346/api/Account/ChangePassword/", content).Result;

            return(result.StatusCode);
        }
Exemple #5
0
        public int ChangePassword(ChangePasswordViewModels changePasswordViewModels)
        {
            Account acc = myContext.Account.Where(a => a.NIK == changePasswordViewModels.NIK).FirstOrDefault();

            acc.Password = Hashing.HashPassword(changePasswordViewModels.NewPassword);
            var result = myContext.SaveChanges();

            return(result);
        }
Exemple #6
0
        public ActionResult ChangePassword(int ID)
        {
            var changePasswordViewModel = new ChangePasswordViewModels()
            {
                ID = ID
            };

            return(View(changePasswordViewModel));
        }
Exemple #7
0
        public ActionResult ChangePassword(ChangePasswordViewModels changePasswordVM)
        {
            var acc = accountRepository.Get(changePasswordVM.NIK);

            if (acc != null)
            {
                if (Hashing.ValidatePassword(changePasswordVM.OldPassword, acc.Password))
                {
                    var data = accountRepository.ChangePassword(changePasswordVM);
                    return(Ok(data));
                }
                else
                {
                    return(StatusCode(404, new { status = "404", message = "Wrong password" }));
                }
            }
            return(NotFound());
        }
        public ActionResult ResetPassword(ChangePasswordViewModels changePasswordViewModels)
        {
            int uid    = (Int32)(Session["id"]);
            var userid = od.users.Find(uid);

            if (userid.password == changePasswordViewModels.OldPassword)
            {
                userid.password        = changePasswordViewModels.NewPassword;
                od.Entry(userid).State = EntityState.Modified;
                od.SaveChanges();
                return(RedirectToAction("Home", "Home"));
            }
            else if (userid.password != changePasswordViewModels.NewPassword)
            {
                changePasswordViewModels.ErrorMsg = "Old Password is not correct !";
                return(View("Index", changePasswordViewModels));
            }
            else
            {
                return(View("Index", changePasswordViewModels));
            }
        }
        public async Task <JsonResult> ChangePassword(ChangePasswordViewModels user)
        {
            IdentityResult result = await _accountService
                                    .ChangePasswordAsync(User.Identity.GetUserId(), user.OldPassword, user.Password);

            if (result.Succeeded)
            {
                return(Json(new
                {
                    isSuccess = true
                }));
            }
            else
            {
                result.Errors.ForEach(x => AddErrors(x));
                return(Json(new
                {
                    isSuccess = false,
                    error = ModelState.FirstOrDefault(x => x.Value.Errors.Any())
                            .Value.Errors.Select(y => y.ErrorMessage).FirstOrDefault()
                }));
            }
        }