public ActionResult PostSupplierPass(PasswordChangeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("ChangePassSupplier"));
            }
            MemberModel model1 = new MemberModel();
            int         memid  = Convert.ToInt32(Session["MemberId"]);

            using (ProjectEntities1 db = new ProjectEntities1())
            {
                var getdata = db.MemberLogins.FirstOrDefault(a => a.MemberId == memid);
                if (model.OldPassword == getdata.Password)
                {
                    if (model.OldPassword == model.NewPassword)
                    {
                        ViewBag.message = "Enter New Password different from Old Password!";
                    }
                    else
                    {
                        db.UpdatePassword(memid, model.NewPassword);
                        ViewBag.message = "Password Updated!";
                    }
                }
                else
                {
                    ViewBag.message = "Old password do not Match";
                }
            }
            return(View("ChangePassSupplier"));
        }
        public async Task ChangePassword_UserNotExists_ReturnsNotFound()
        {
            // Arrange
            var mockConfiguration = new Mock <Microsoft.Extensions.Configuration.IConfiguration>();
            var mockLogger        = new Mock <ILogger <AccountController> >();
            var mockUmService     = new Mock <IUserManagementService>();
            var mockMapper        = new Mock <IMapper>();
            var mockHelperService = new Mock <IHelperService>();

            var controller = new UsersController(mockConfiguration.Object, mockLogger.Object,
                                                 mockUmService.Object, mockMapper.Object, mockHelperService.Object);

            mockUmService.Setup(umService => umService.FindUserAsync("a"))
            .ReturnsAsync((ApplicationUser)null)
            .Verifiable();

            var passwordChangeModel = new PasswordChangeModel()
            {
                Password        = "******",
                ConfirmPassword = "******"
            };

            // Act
            var result = await controller.ChangeUserPassword("a", passwordChangeModel);

            // Assert
            var actionResult = Assert.IsType <NotFoundResult>(result);

            mockUmService.Verify();
        }
Пример #3
0
        public ActionResult ChangePassword(PasswordChangeModel model)
        {
            if (ModelState.IsValid)
            {
                KodlatvUser user = kodlatvusermanager.Find(x => x.ActivateGuid == model.PasswordGuid);

                if (user == null)
                {
                    BusinessLayerResult <KodlatvUser> layerResult = new BusinessLayerResult <KodlatvUser>();
                    layerResult.AddError(ErrorMessageCode.UserCouldNotFind, "Kullanıcı Bulunamadı.");
                    ErrorViewModel errorNotifyObj = new ErrorViewModel()
                    {
                        Items          = layerResult.Errors,
                        Title          = "Kullanıcı Bulunamadı.",
                        RedirectingUrl = "/Other/ChangePassword" + model.PasswordGuid
                    };

                    return(View("Error", errorNotifyObj));
                }
                else
                {
                    user.Password = model.Password;
                    kodlatvusermanager.Uptade(user);
                    //TODO
                    return(Redirect("/Home/Login"));
                }
            }
            return(View(model));
        }
Пример #4
0
        public ResponseModel ChangeForgatPasswordUser(PasswordChangeModel obj)
        {
            ResponseModel result = new ResponseModel();

            result = ValidateForgatChangePasswordModel(obj);

            if (!result.IsSuccess)
            {
                return(result);
            }

            Guid parseGuid = Guid.Parse(obj.ProcessGuid);
            var  mail      = _passRepo.GetByCustomQuery("select * from PasswordChangeMails where ChangeGuid = @Guid", new { Guid = parseGuid }).FirstOrDefault();

            var user = _userM.GetUserByID(mail.UserID);

            user.Password    = Encryption.GenerateMD5(obj.Password);
            result.IsSuccess = _userM.UpdateUser(user);

            if (!result.IsSuccess)
            {
                result.Message = "İşlemlerle ilgili  bir sorun oluştu.Sistem yöneticinize başvurun!";
                return(result);
            }
            result.IsSuccess = true;
            result.Message   = "Şifreniz başarı ile değiştirilmiştir.Lütfen giriş yapmayı deneyiniz!";
            return(result);
        }
Пример #5
0
        public ResponseModel ChangePasswordUser(PasswordChangeModel obj)
        {
            ResponseModel result = new ResponseModel();

            result = ValidateChangePasswordModel(obj);

            if (!result.IsSuccess)
            {
                return(result);
            }

            var user = _userM.GetUserByID(obj.UserID);

            user.Password    = Encryption.GenerateMD5(obj.Password);
            result.IsSuccess = _userM.UpdateUser(user);

            if (!result.IsSuccess)
            {
                result.Message = "İşlemlerle ilgili  bir sorun oluştu.Sistem yöneticinize başvurun!";
                return(result);
            }
            result.IsSuccess = true;
            result.Message   = "Şifreniz başarı ile değiştirilmiştir.";
            return(result);
        }
Пример #6
0
        public ResponseModel ValidateForgatChangePasswordModel(PasswordChangeModel obj)
        {
            ResponseModel result = new ResponseModel();

            if (string.IsNullOrWhiteSpace(obj.Password) || string.IsNullOrWhiteSpace(obj.PasswordAgain))
            {
                result.Message = "Şifreler zorunlu alanlardır.";
                return(result);
            }

            if (obj.Password.Length < 6)
            {
                result.Message = "Şifre en az 6 haneli olmalıdır!";
                return(result);
            }

            if (obj.Password != obj.PasswordAgain)
            {
                result.Message = "Şifreler uyuşmamaktadır!";
                return(result);
            }

            if (string.IsNullOrWhiteSpace(obj.ProcessGuid))
            {
                result.Message = "İşlem süreçleri ile ilgili bir sorun var.";
                return(result);
            }

            result.IsSuccess = true;
            return(result);
        }
Пример #7
0
        public ResponseModel ValidateChangePasswordModel(PasswordChangeModel obj)
        {
            ResponseModel result = new ResponseModel();

            if (string.IsNullOrWhiteSpace(obj.OldPassword) || string.IsNullOrWhiteSpace(obj.Password) || string.IsNullOrWhiteSpace(obj.PasswordAgain))
            {
                result.Message = "Şifreler zorunlu alanlardır.";
                return(result);
            }

            var user = _userM.GetUserByID(obj.UserID);

            if (user.Password != Encryption.GenerateMD5(obj.OldPassword))
            {
                result.Message = "Mevcut şifre bilgileri yanlış!";
                return(result);
            }

            if (obj.Password.Length < 6)
            {
                result.Message = "Şifre en az 6 haneli olmalıdır!";
                return(result);
            }

            if (obj.Password != obj.PasswordAgain)
            {
                result.Message = "Yeni Şifreler uyuşmamaktadır!";
                return(result);
            }

            result.IsSuccess = true;
            return(result);
        }
        public ActionResult PasswordChange(PasswordChangeModel passwordChangeModel)
        {
            try
            {
                if (passwordChangeModel.Password == passwordChangeModel.ConfirmPassword)
                {
                    var userManager = AppUserManager.Create(null, HttpContext.GetOwinContext());
                    var authManager = HttpContext.GetOwinContext().Authentication;
                    var userId      = User.Identity.GetUserId();

                    var result = userManager.ChangePassword(userId, passwordChangeModel.CurrentPassword, passwordChangeModel.Password);
                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, string.Join(",", result.Errors));
                        return(View(passwordChangeModel));
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Passwords don't match!");
                    return(View(passwordChangeModel));
                }
            }
            catch
            {
                return(View());
            }
        }
Пример #9
0
        public ActionResult ChangePassword(PasswordChangeModel model)
        {
            this.EnsureStockwinnersMember();

            if (ModelState.IsValid)
            {
                // ChangePassword will throw an exception rather
                // than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    MembershipUser currentUser = Membership.GetUser(Authentication.GetCurrentUserIdentity().EmailAddress, userIsOnline: true);
                    changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    return(RedirectToAction("ChangePasswordSuccess"));
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #10
0
        public IActionResult ChangeMyPassword(PasswordChangeModel model)
        {
            if (ModelState.IsValid)
            {
                AppUser user = CurrentUser;

                if (user != null)
                {
                    bool exist = Usermanager.CheckPasswordAsync(user, model.PasswordOld).Result;
                    if (exist)
                    {
                        IdentityResult result = Usermanager.ChangePasswordAsync(user, model.PasswordOld, model.PasswordNew
                                                                                ).Result;
                        if (result.Succeeded)
                        {
                            Usermanager.UpdateSecurityStampAsync(user);
                            SignInManager.SignOutAsync();
                            SignInManager.PasswordSignInAsync(user, model.PasswordNew, false, false);

                            ViewBag.success = true;
                        }
                        else
                        {
                            AddErrors(result);
                        }
                    }
                }
            }
            return(View(model));
        }
Пример #11
0
        public Task <Operation> ChangePassword(PasswordChangeModel model)
        {
            return(Operation.Run(() =>
            {
                if (model == null)
                {
                    throw new Exception("Password change cannot be null");
                }


                model.Validate();

                var user = _db.Set <User>().SingleOrDefault(c => c.UserId == model.UserId);

                if (user == null)
                {
                    throw new Exception("User not found ");
                }

                bool flag = false;

                flag = EncryptPassword(model.OldPassword, user.Salt) == user.Password;
                if (flag)
                {
                    user.Password = EncryptPassword(model.NewPassword, user.Salt);
                    _db.Update <User>(user);
                    _db.SaveChanges();
                    return Task.CompletedTask;
                }
                else
                {
                    throw new Exception("Please enter your old password correctly");
                }
            }));
        }
Пример #12
0
        public virtual ActionResult ChangePassword(PasswordChangeModel model)
        {
            //添加验证修改密码不能与原密码一致
            if (model.OldPassword == model.Password)
            {
                return(JsonTips("error", FStr.NewPassowrdMustNotEqualToOld));
            }

            var        IsLogin  = Request["IsLogin"];
            LoginState resState = AppManager.Instance.StateProvider.ChangePassword(model);

            if (LoginState.OK == resState)
            {
                //修改默认的初始密码跳转到登录页, 首页修改密码后跳转到桌面
                //if (IsLogin != null && IsLogin.ToUpper() == "TRUE")
                //    return JsonTipsLang("success", null, "Password_Change_Success", new { Url = Url.Action("Logout", "Account") });
                //return JsonTipsLang("success", null, "Password_Change_Success", new { Url = Url.Action("StartPage", "Home") });

                //修改默认的初始密码跳转到登录页
                AppManager.Instance.Logout(User.Identity.Name);
                this.ClearLoginModel();
                return(JsonTipsLang("success", null, FStr.PasswordChangeSucceed, new { Url = Url.Action("Logout", "Account") }));
            }
            return(JsonTipsLang("error", null, resState.ToString()));
        }
        public ActionResult ChangePassword(PasswordChangeModel PM)
        {
            if (!LoggedIn())
            {
                return(RedirectToAction("Login", "Auth"));
            }

            if (isAdmin())
            {
                return(RedirectToAction("Index", "Admin"));
            }

            if (!isAdmin() && !isAuthor())
            {
                return(RedirectToAction("Logout", "Auth"));
            }

            Author author = authorHelper.GetById(GetAuthorId());

            if (Hash(PM.OldPassword) == author.Password && PM.NewPassword == PM.ConfirmPassword)
            {
                author.Password = Hash(PM.NewPassword);
                authorHelper.Update(author);

                return(RedirectToAction("Profile"));
            }
            else
            {
                ModelState.AddModelError("", "Invalid form data!");
                return(View(PM));
            }
        }
Пример #14
0
        public ActionResult PostAdminPassword(PasswordChangeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("AdminChangePass"));
            }
            int memid = Convert.ToInt32(Session["AdminId"]);

            using (ProjectEntities1 db = new ProjectEntities1())
            {
                var getdata = db.Admins.FirstOrDefault(a => a.AdminId == memid);
                if (model.OldPassword == getdata.Password)
                {
                    if (model.OldPassword == model.NewPassword)
                    {
                        ViewBag.message = "Enter New Password different from Old Password!";
                    }
                    else
                    {
                        db.UpdateAdminPassword(memid, model.NewPassword);
                        ViewBag.message = "Password Updated!";
                    }
                }

                else
                {
                    ViewBag.message = "Old password didn't match!";
                }
            }
            return(View("AdminChangePass"));
        }
Пример #15
0
        public ActionResult PasswordChange(PasswordChangeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (_authenticationService.ValidateAuthenticationData(ScpContext.User.Login, model.OldPassword) == false)
            {
                AddMessage(MessageType.Error, Resources.Messages.OldPasswordIsNotCorrect);

                return(View(model));
            }

            ScpContext.Services.Organizations.SetUserPassword(
                ScpContext.User.ItemId, ScpContext.User.AccountId,
                model.PasswordEditor.NewPassword);

            var user = _authenticationService.LogIn(ScpContext.User.Login, model.PasswordEditor.NewPassword);

            _authenticationService.CreateAuthenticationTicket(user);

            AddMessage(MessageType.Success, Resources.Messages.PasswordSuccessfullyChanged);

            return(RedirectToRoute(AccountRouteNames.UserProfile));
        }
Пример #16
0
        public async Task <IActionResult> EditPassword([FromBody] PasswordChangeModel passwordModel)
        {
            var user = await userManager.GetUserAsync(HttpContext.User);

            if (user != null)
            {
                if (String.IsNullOrWhiteSpace(passwordModel.oldPassword) || String.IsNullOrWhiteSpace(passwordModel.newPassword) || String.IsNullOrWhiteSpace(passwordModel.newPasswordConfirm))
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new AuthResponse {
                        Status = "Error", Message = "Provided password was in incorrect format"
                    }));
                }

                if (passwordModel.newPassword.Equals(passwordModel.newPasswordConfirm))
                {
                    try
                    {
                        await userManager.ChangePasswordAsync(user, passwordModel.oldPassword, passwordModel.newPassword);

                        return(Ok(new { user, response = new AuthResponse {
                                            Status = "Success", Message = "Changes saved successfully"
                                        } }));
                    }
                    catch (Exception ex)
                    {
                        return(StatusCode(StatusCodes.Status400BadRequest, new AuthResponse {
                            Status = "Error", Message = "Provided old password was incorrect"
                        }));
                    }
                }
            }
            return(StatusCode(StatusCodes.Status400BadRequest, new AuthResponse {
                Status = "Error", Message = "User not found!"
            }));
        }
Пример #17
0
        public IActionResult ProfileEditPassword(PasswordChangeModel data)
        {
            var user = _dbContext.Users.ById(User.GetId()).FirstOrDefault();

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

            if (user.HashedPassword != AccountController.HashPassword(data.OldPassword))
            {
                TempData["PasswordNotMatch"] = "Старый пароль не совпадает.";
                ModelState.AddModelError("", "Старый пароль не совпадает.");
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("ProfileEdit"));
            }

            user.HashedPassword = AccountController.HashPassword(data.NewPassword);
            _dbContext.SaveChanges();
            TempData["PasswordChangeSuccess"] = true;

            return(RedirectToAction("ProfileEdit"));
        }
Пример #18
0
        public async Task <IActionResult> PasswordChange([FromBody] PasswordChangeModel model)
        {
            try
            {
                if (!ModelState.IsValid || model == null)
                {
                    return(BadRequest(NotificationCodes.RequiredInput));
                }

                var user = await this.userManager.FindByIdAsync(model.UserId);

                if (user == null)
                {
                    return(BadRequest(NotificationCodes.NoUserExists));
                }

                await userManager.ChangePasswordAsync(user, model.CurrentPassword, model.NewPassword);

                var result = await this.userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    return(Ok(NotificationCodes.PasswordSuccessfullyChanged));
                }
                return(BadRequest());
            }
            catch
            {
                return(BadRequest());
            }
        }
Пример #19
0
        public virtual LoginState ChangePassword(PasswordChangeModel model)
        {
            var _context = new ModelContext();

            // var user = _context.UserProfiles.Find(2);
            MemberShip member = _context.Set <MemberShip>().FirstOrDefault(m => m.UserName.Equals(
                                                                               Thread.CurrentPrincipal.Identity.Name,
                                                                               StringComparison.OrdinalIgnoreCase));

            if (member == null)
            {
                return(LoginState.UserNotExist);
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(LoginState.PasswordError);
            }

            if (EncryptPassword(model.OldPassword, member.PasswordSalt) != member.Password)
            {
                return(LoginState.OldPasswordError);
            }

            member.PasswordSalt        = CommOp.NewId();
            member.Password            = Encryption.MD5(model.Password + member.PasswordSalt);
            member.PasswordChangedDate = DateTime.Now;
            _context.SaveChanges();
            return(LoginState.OK);
        }
        public override ActionResult GenerateView(Response response)
        {
            PasswordChangeModel model = new PasswordChangeModel();

            model.PasswordResetHash = ((HashValidated)response).passwordResetHash;
            return(new ActionResult("~/Areas/Public/Views/ResetPassword/PasswordChangeForm.cshtml", model));
        }
        public JsonResult changePassword(PasswordChangeModel changeModel)
        {
            ResponseModel result = new ResponseModel();

            result = _regM.ChangeForgatPasswordUser(changeModel);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        private async System.Threading.Tasks.Task ChangeUserPassword()
        {
            if (PasswordChangeModel.ValidateModel())
            {
                try
                {
                    bool success = await _adminService.ChangeUserPasswordAsync(CurrentUser, PasswordChangeModel.OldPassword, PasswordChangeModel.NewPassword, PasswordChangeModel.NewPassword2);

                    if (success)
                    {
                        ChangeNotification.Raise(new Notification()
                        {
                            Title   = Properties.Resources.PasswordChange_Title,
                            Content = Properties.Resources.PasswordChange_Success
                        });
                        IsPasswordInEditMode      = false;
                        _userCredentials.Password = PasswordChangeModel.NewPassword;
                        _userCredentials.UpdateCredentialsForAllFactories();
                    }
                    else
                    {
                        ChangeNotification.Raise(new Notification()
                        {
                            Title   = Properties.Resources.PasswordChange_Title,
                            Content = Properties.Resources.PasswordChange_Failed
                        });
                    }
                }
                catch (TimeoutException timeoutEx)
                {
                    _eventAggregator.GetEvent <TimeoutErrorEvent>().Publish(timeoutEx);
                }
            }
        }
        public JsonResult changePassword(PasswordChangeModel changeModel)
        {
            ResponseModel result = new ResponseModel();

            changeModel.UserID = CurrentUser.CurrentUser.ID;
            result             = _regM.ChangePasswordUser(changeModel);
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #24
0
        public async Task <IdentityResult> ChangePassword(PasswordChangeModel changeModel)
        {
            var user = await _userManager.GetUserAsync(_user);

            var passwordChangeResult = await _userManager.ChangePasswordAsync(user, changeModel.OldPassword, changeModel.NewPassword);

            return(passwordChangeResult);
        }
Пример #25
0
        public ActionResult ChangeSubmit(PasswordChangeModel model)
        {
            var claim = ClaimsPrincipal.Current.FindFirst("SAMAccountName");

            if (claim == null || String.IsNullOrEmpty(claim.Value))
            {
                ModelState.AddModelError("", "The SAMAccountName is not available.");
            }

            if (String.IsNullOrEmpty(User.Identity.Name))
            {
                ModelState.AddModelError("", "The name of the user is not available.");
            }

            if (!ModelState.IsValid)
            {
                return(View("Change"));
            }

            try
            {
                // Update password.
                using (var context = new PrincipalContext(ContextType.Domain, ConfigurationManager.AppSettings["AdDomain"], ConfigurationManager.AppSettings["AdBase"], ClaimsPrincipal.Current.FindFirst("SAMAccountName").Value, model.OldPassword))
                {
                    using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, ClaimsPrincipal.Current.FindFirst("SAMAccountName").Value))
                    {
                        user.ChangePassword(model.OldPassword, model.NewPassword);
                    }
                }

                // Generate a JWT for the redirect rule.
                var now             = DateTime.UtcNow;
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject = new ClaimsIdentity(new[] {
                        new Claim("sub", ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value),
                        new Claim("aud", ConfigurationManager.AppSettings["auth0:ClientId"]),
                        new Claim("pwd_change", "true")
                    }),
                    TokenIssuerName    = ConfigurationManager.AppSettings["auth0:Domain"],
                    Lifetime           = new Lifetime(now, now.AddMinutes(10)),
                    SigningCredentials = new SigningCredentials(
                        new InMemorySymmetricSecurityKey(TextEncodings.Base64Url.Decode(ConfigurationManager.AppSettings["auth0:ClientSecret"])),
                        "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
                        "http://www.w3.org/2001/04/xmlenc#sha256"),
                };

                // Redirect back to Auth0.
                var handler       = new JwtSecurityTokenHandler();
                var securityToken = handler.CreateToken(tokenDescriptor);
                return(Redirect(ConfigurationManager.AppSettings["auth0:Domain"] + "continue?token=" + handler.WriteToken(securityToken)));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View("Change"));
            }
        }
 private void StartPasswordChange()
 {
     if (IsUserInEditMode)
     {
         CancelUserChanges();
     }
     PasswordChangeModel.Reset();
     IsPasswordInEditMode = true;
 }
        public async Task <IActionResult> Authenticate([FromBody] PasswordChangeModel model)
        {
            var result = await userService.UpdatePasswordAsync(model);

            if (!result)
            {
                return(BadRequest());
            }
            return(Ok());
        }
        public void Update(PasswordChangeModel passwordChangeModel)
        {
            ApplicationUser user = context.Users.Find(passwordChangeModel.Id);

            userManager.ChangePasswordAsync(user, passwordChangeModel.OldPassword, passwordChangeModel.NewPassword).Wait();

            user.UserName             = passwordChangeModel.Username;
            context.Entry(user).State = EntityState.Modified;
            context.SaveChanges();
        }
Пример #29
0
        public async Task <IActionResult> ChangePassword(PasswordChangeModel model)
        {
            if (ModelState.IsValid && !(model is null))
            {
                var student = await GetCurrentStudentAsync().ConfigureAwait(false);

                student.Password = model.NewPassword;
                _ = Db.SaveChangesAsync();
            }
            return(View(model));
        }
        private async Task ChangePasswordAsync()
        {
            if (!PasswordChangeModel.IsValid())
            {
                return;
            }

            await userFacade.ChangeUserPasswordAsync(PasswordChangeModel);

            InitPasswordChangeModel(currentUserProvider.CurrentUser);
        }