Beispiel #1
0
        public string ChangePassword(DTOChangePasswordViewModel dtoChangePasswordViewModel)
        {
            var password         = new UserPasswordValidator();
            var validatePassword = password.ValidateAsync(dtoChangePasswordViewModel.NewPassword).Result;

            if (validatePassword.Errors.Count() > 0)
            {
                return(validatePassword.Errors.First());
            }

            var userCurrent = Database.GetManager(dtoChangePasswordViewModel.Login);

            if (userCurrent == null)
            {
                return("Close this window and reset program.");
            }

            var result = Database.UserManager.ChangePassword(userCurrent.Id, dtoChangePasswordViewModel.OldPassword, dtoChangePasswordViewModel.NewPassword);

            if (result.Succeeded)
            {
                return(null);
            }
            return(result.Errors.First());
        }
Beispiel #2
0
        private void CheckPasswords()
        {
            DTOChangePasswordViewModel dtoChangePasswordViewModel = new DTOChangePasswordViewModel()
            {
                Login       = LoginUser,
                OldPassword = OldPasswordBox.Text,
                NewPassword = NewPasswordBox.Text
            };

            string errors = UserService.ChangePassword(dtoChangePasswordViewModel);

            if (errors == null)
            {
                MessageBox.Show("Password is changed");
                Close();
            }
            ChangePassword_Validation.Text = errors;
        }
Beispiel #3
0
        public async Task <OperationDetails> ChangePassword(DTOChangePasswordViewModel changePasswordViewModelDto)
        {
            var password         = new UserPasswordValidator();
            var validatePassword = password.ValidateAsync(changePasswordViewModelDto.NewPassword).Result;

            if (validatePassword.Errors.Count() > 0)
            {
                return(new OperationDetails(false, validatePassword.Errors.FirstOrDefault(), ""));
            }

            var result = await Database.UserManager.ChangePasswordAsync(changePasswordViewModelDto.UserId, changePasswordViewModelDto.OldPassword,
                                                                        changePasswordViewModelDto.NewPassword);

            if (result.Succeeded)
            {
                return(new OperationDetails(true, "", ""));
            }
            return(new OperationDetails(false, result.Errors.FirstOrDefault(), ""));
        }