public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordVm model) { if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(ModelState.GetModelErrors())); } try { var user = await _userManager.FindByEmailAsync(HttpContext.User.Identity.Name); if (user != null) { var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (result == IdentityResult.Success) { return(Ok(new { })); } } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new[] { "Unable to change password" })); } catch (Exception ex) { _logger.LogError(1, ex, "Unable to change password"); return(BadRequest()); } }
public async Task <IActionResult> ChangePassword(ChangePasswordVm changePassword) { if (User.Identity.IsAuthenticated && User.IsInRole("admin")) { AppUser currUser = await _userManager.GetUserAsync(User); if (currUser == null || !ModelState.IsValid) { return(View(changePassword)); } if (!await _userManager.CheckPasswordAsync(currUser, changePassword.OldPassword)) { ModelState.AddModelError("", "Köhnə şifrə düzgün deyil"); return(View(changePassword)); } if (changePassword.Password != changePassword.ConfirmPassword) { ModelState.AddModelError("", "Şifrəni düzgün təsdiqləyin"); return(View(changePassword)); } var password = _configuration.GetValue <string>("Passwords:AdminPassword"); await _userManager.ChangePasswordAsync(currUser, password, changePassword.ConfirmPassword); await _context.SaveChangesAsync(); return(PartialView("PasswordChanged")); } return(RedirectToAction(nameof(Index))); }
public ActionResult CheckPassword(ChangePasswordVm data) { var userId = User.Identity.GetUserId(); var appUser = service.Uow.Users.FindById(userId); if (!service.Uow.Users.CheckPassword(appUser, data.CurrentPassword)) { return(Json(new { isPasswordCorrect = false, isNewPasswordConfirmed = true })); } else if (data.NewPassword != data.NewPasswordConfirm) { return(Json(new { isNewPasswordConfirmed = false, isPasswordCorrect = true })); } else { return(Json(new { isNewPasswordConfirmed = true, isPasswordCorrect = true })); } }
public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordVm model) { if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(ModelState.GetModelErrors())); } try { var user = await _userManager.FindByEmailAsync(HttpContext.User.Identity.Name); if (user != null) { var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (result == IdentityResult.Success) { return(Ok(new { })); } } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new [] { "Unable to change password" })); } catch (Exception ex) { _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); return(BadRequest()); } }
public async Task <IActionResult> ChangePassword(ChangePasswordVm model) { if (!ModelState.IsValid) { return(View(model)); } var user = await userManager.GetUserAsync(User); if (user == null) { return(RedirectToAction("Login")); } var result = await userManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword); if (result.Succeeded) { TempData["Success"] = "Password was changed successfully."; return(View("ChangePasswordSuccess")); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(View(model)); } }
public async Task <ValidationResultVm> ChangePasswordValidationAsync(ChangePasswordVm changePasswordVm, long userId) { _changePasswordVm = changePasswordVm; await DoValidationAsync(userId); return(ValidationResultVm); }
public ActionResult ChangePassword(ChangePasswordVm data) { var user = service.Uow.Users.FindById(User.Identity.GetUserId()); if (service.Uow.Users.CheckPassword(user, data.CurrentPassword) && (data.NewPassword == data.NewPasswordConfirm)) { service.Uow.Users.ChangePassword(user.Id, data.CurrentPassword, data.NewPassword); } return(RedirectToAction("Details")); }
public async Task <ResultModel <EResultStatus> > ChangePasswordAsync(ChangePasswordVm appUserChangePasswordVm) { await ValidationChangePasswordAsync(appUserChangePasswordVm); if (HasError) { return(CreateInvalidResult <EResultStatus>()); } var result = await _appUserService .ChangePasswordAsync(appUserChangePasswordVm.NewPassword, UserId); return(CreateResult(result)); }
public ActionResult ChangePassword(ChangePasswordVm data) { var userId = User.Identity.GetUserId(); var appUser = unitOfWork.Membership.Users.FindById(userId); if (unitOfWork.Membership.Users.CheckPassword(appUser, data.Password)) { if (data.NewPassword == data.NewPasswordConfirm) { unitOfWork.Membership.Users.ChangePassword(userId, data.Password, data.NewPassword); } } return(RedirectToAction("Profile", "Account")); }
public async Task <ActionResult> ChangePassword(ChangePasswordVm data) { using (_entities) { //Confirm that model is valid if (!ModelState.IsValid) { return(View(data)); } var userMasterId = Convert.ToInt64(CookieHelper.GetCookie(CookieName.UserMasterId)); var userMaster = await _entities.UserMasters.FindAsync(userMasterId); if (userMaster != null) { var oldHashValue = userMaster.Hash; var salt = userMaster.Salt; var isValidOldPwd = Utilities.CompareHashValue(data.OldPassword.Trim(), userMaster.Email, oldHashValue, salt); if (isValidOldPwd) { //Create HASH & SALT var newSalt = Utilities.GenerateSalt(32); var hash = Utilities.GenerateHash(data.NewPassword.Trim(), userMaster.Email.Trim(), newSalt); userMaster.Salt = newSalt; userMaster.Hash = hash; _entities.Entry(userMaster).State = EntityState.Modified; await _entities.SaveChangesAsync(); TempData["Success"] = "Password changed successfully."; } else { TempData["Error"] = "You entered wrong old password."; } } else { TempData["Error"] = "Request failed! Please try after some time."; } return(View(new ChangePasswordVm())); } }
public PartialViewResult ChangePassword(ChangePasswordVm model) { if (ModelState.IsValid) { try { _userService.ChangePassword(model.NewPassword, model.OldPassword); ViewData[Constants.ViewBagMessageKey] = "You password has been changed successfully."; return(PartialView(Routes.ViewDataMsgView)); } catch (SimpleException ex) { ModelState.AddModelError("", ex.Message); } } return(PartialView(model)); }
public ActionResult ChangePassword(ChangePasswordVm data) { var cus = db.Accounts.Find(data.Id); if (!cus.Password.Equals(MySecurity.EncryptPass(data.OldPassword))) { ViewBag.Message = "Wrong password!"; } else { cus.Password = MySecurity.EncryptPass(data.Password); db.SaveChanges(); return(RedirectToAction("UpdateProfile", new { id = cus.CustomerId })); } return(View(data)); }
public ActionResult ResetPassword(ChangePasswordVm model, string id) { if (ModelState.IsValid) { try { _userService.ResetPassword(id, model.NewPassword); TempData[Constants.ViewBagMessageKey] = "Your password has been changed successfully. Kindly login."; return(SafeRedirect(Routes.Login)); } catch (SimpleException ex) { ModelState.AddModelError("", ex.Message); } } return(View(model)); }
public ActionResult ChangePassword(ChangePasswordVm data) { var emp = db.Employees.Find(data.Id); if (!emp.Password.Equals(MySecurity.EncryptPass(data.OldPassword))) { ViewBag.Message = "Wrong password!"; } else { emp.Password = MySecurity.EncryptPass(data.Password); db.SaveChanges(); return(RedirectToAction("UserProfile", new { id = data.Id })); } return(View(data)); }
public virtual async Task <IActionResult> ChangePassword([FromBody] ChangePasswordVm model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await UserManager.FindByIdAsync(UserId.ToString()); var result = await UserManager.ChangePasswordAsync(user, model.Current, model.NewPass); if (result.Succeeded) { return(Ok()); } AddErrors(result); return(BadRequest(ModelState)); }
public string ChangePassword(ChangePasswordVm view) { if (!ModelState.IsValid) { return(PostReturnVals.Failed); } view.ProviderKey = CurrentUserProviderToken; var resp = RestUnitOfWork.UserSvc.ChangePassword(view.ProviderKey, view); if (resp.IsSuccess) { FormsAuthentication.SignOut(); return(PostReturnVals.Success); } else { return(resp.Message); } }
public async Task <Option <UserServiceModel, Error> > ChangePasswordAsync(ChangePasswordVm model) { var user = await DbContext .Users .Where(u => u.Id == model.UserId) .FirstOrDefaultAsync(); var result = await UserManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (!result.Succeeded) { return(None <UserServiceModel, Error>(new Error(result.Errors.Select(e => e.Description)))); } await SignInManager.SignInAsync(user, isPersistent : false); return(new UserServiceModel { Id = user.Id, Email = user.Email }.Some <UserServiceModel, Error>()); }
public ActionResult ChangePassword(int?id) { if (id != int.Parse(User.Identity.Name)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Employee employee = db.Employees.Find(id); if (employee == null) { return(HttpNotFound()); } ChangePasswordVm change = new ChangePasswordVm() { Id = employee.Id, Username = employee.Username }; return(View(change)); }
public ActionResult ChangePassword(int?id) { if (id != int.Parse(User.Identity.Name)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Account acc = db.Accounts.Find(id); if (acc == null) { return(HttpNotFound()); } ChangePasswordVm change = new ChangePasswordVm() { Id = acc.Id, Username = acc.Username }; return(View(change)); }
public void ChangeUserPassword(ChangePasswordVm model) { var userExists = _identityDbContext.ApplicationUsers.SingleOrDefault(p => p.Email == model.UserEmail); if (userExists == null) { throw new Exception("Пользователь с таким мэйлом отсутствует в системе"); } var passwordCheck = _identityDbContext.ApplicationUserPasswordHistories .Where(p => p.Password == model.UserPassword && p.ApplicationUserId == userExists.Id) .OrderByDescending(p => p.SetupDate).Take(1); if (passwordCheck == null) { throw new Exception("Неправильный пароль"); } var userPasswordHistory = _identityDbContext.ApplicationUserPasswordHistories .Where(p => p.ApplicationUser.Email == model.UserEmail).OrderByDescending(p => p.SetupDate).Take(5); bool passwordValidationCheck = true; foreach (var item in userPasswordHistory) { if (item.Password == model.UserNewPassword) { passwordValidationCheck = false; } } if (!passwordValidationCheck) { throw new Exception("Данный пароль уже использовался выберите другой"); } if (model.UserNewPassword != model.UserNewPasswordConfirmed) { throw new Exception("Новый пароль не соответствует подтвержденному"); } ApplicationUserPasswordHistory ApplicationUserPasswordHistory = new ApplicationUserPasswordHistory() { ApplicationUserId = userExists.Id, Password = model.UserNewPassword, SetupDate = DateTime.Now, InvalidatedDate = DateTime.Now.AddMonths(3) }; _identityDbContext.ApplicationUserPasswordHistories.Add(ApplicationUserPasswordHistory); var userIsActive = _identityDbContext.ApplicationUsers.SingleOrDefault(p => p.Email == model.UserEmail && p.IsActive == false); if (userIsActive != null) { userIsActive.IsActive = true; } _identityDbContext.SaveChanges(); }
private async Task ValidationChangePasswordAsync(ChangePasswordVm appUserChangePasswordVm) { ValidationResultVm = await _appUserChangePasswordValidationService .ChangePasswordValidationAsync(appUserChangePasswordVm, UserId); }
public ActionResult ChangeUserPassword(ChangePasswordVm data) { service.Uow.Users.RemovePassword(data.UserId); service.Uow.Users.AddPassword(data.UserId, data.Password); return(RedirectToAction("List")); }
public ChangePasswordViewController() { _changePasswordVm = ServiceLocator.Current.GetInstance <ChangePasswordVm>(); _navigationService = ServiceLocator.Current.GetInstance <INavigationService>(); }
/// <summary> /// Change the password of the existing user globaly /// </summary> /// <param name="loginProviderKey">loginProviderKey</param> /// <param name="changePassword">ChangePasswordVm</param> /// <returns>Message</returns> public (string Message, bool IsSuccess) ChangePassword(string loginProviderKey, ChangePasswordVm changePassword) { if (string.IsNullOrWhiteSpace(changePassword.NewPassword)) { return("Password needs to have alphanumeric characters.", false); } if (changePassword.NewPassword != changePassword.ConfirmPassword) { return("Confirm password did not match.", false); } var resp = Post <string>(API_MEMBER_BASE + "ChangePassword/", new { ProviderKey = loginProviderKey, OldPassword = changePassword.OldPassword, NewPassword = changePassword.NewPassword, ConfirmPassword = changePassword.ConfirmPassword }); return(resp.Response, resp.IsSuccess); }
public async Task <ApiResult> ChangePassword(ChangePasswordVm model) { await _userService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword, model.ConfirmPassword); return(ApiResult.Ok); }
public async Task <IActionResult> ChangePassword(ChangePasswordVm model) { model.UserId = User.Identity.GetUserId(); return((await _manageService.ChangePasswordAsync(model)) .Match(RedirectToLocal, ChangePasswordError)); }