private bool CheckInputData()
        {
            bool result = true;

            ClearError();
            if (Password.Trim() == string.Empty)
            {
                VisibleErrPassword = true;
                StringErrPassword  = "******";
                result             = false;
            }
            if (NewPassword.Trim() == string.Empty)
            {
                VisibleErrNewPassword = true;
                StringErrNewPassword  = "******";
                result = false;
            }
            if (ReNewPassword.Trim() == string.Empty)
            {
                VisibleErrReNewPassword = true;
                StringErrReNewPassword  = "******";
                result = false;
            }
            if (NewPassword.Trim() != string.Empty && ReNewPassword.Trim() != string.Empty && NewPassword != ReNewPassword)
            {
                VisibleErrReNewPassword = true;
                StringErrReNewPassword  = "******";
                result = false;
            }
            return(result);
        }
Example #2
0
        public void Validate()
        {
            if (!string.IsNullOrEmpty(NewPassword))
            {
                NewPassword = NewPassword.Trim();
            }

            if (string.IsNullOrEmpty(NewPassword))
            {
                LocalFunctions.AddError("Please enter new password", MethodBase.GetCurrentMethod(), false, false);
            }
            else
            {
                if (NewPassword.Length < 6)
                {
                    LocalFunctions.AddError("Password min lenght should be 6", MethodBase.GetCurrentMethod(), false, false);
                }

                if (NewPassword.Length > 30)
                {
                    LocalFunctions.AddError("Password max lenght is 30", MethodBase.GetCurrentMethod(), false, false);
                }
            }


            if (!string.IsNullOrEmpty(ConfirmPassword))
            {
                ConfirmPassword = ConfirmPassword.Trim();
            }

            if (string.IsNullOrEmpty(ConfirmPassword))
            {
                LocalFunctions.AddError("Please enter confirm password", MethodBase.GetCurrentMethod(), false, false);
            }
            else if (ConfirmPassword != NewPassword)
            {
                LocalFunctions.AddError("Confirm password is not same", MethodBase.GetCurrentMethod(), false, false);
            }


            if (!string.IsNullOrEmpty(EmailedCode))
            {
                EmailedCode = EmailedCode.Trim();
            }

            if (string.IsNullOrEmpty(EmailedCode))
            {
                LocalFunctions.AddError("Please enter emailed code", MethodBase.GetCurrentMethod(), false, false);
            }
            else
            {
                if (EmailedCode.Length != 10)
                {
                    LocalFunctions.AddError("Emailed code lenght should be 10", MethodBase.GetCurrentMethod(), false, false);
                }
            }
        }
Example #3
0
        public void Update()
        {
            using (var db = new SMSContext())
            {
                var admin = db.Admins.FirstOrDefault(a => a.username == Username);

                admin.password = NewPassword.Trim();

                db.SaveChanges();
            }
        }
Example #4
0
        /// <summary>
        /// 保存密码
        /// </summary>
        private void SavePassword()
        {
            if (OldPassword != null && NewPassword != null && ConfirmPassword != null)
            {
                string oldPassword     = ClientHelper.Encryption(OldPassword.Trim());
                string newPassword     = ClientHelper.Encryption(NewPassword.Trim());
                string confirmPassword = ClientHelper.Encryption(ConfirmPassword.Trim());
                if (newPassword.Length >= 6 && newPassword.Equals(confirmPassword))
                {
                    if (HomeViewModel.RequestResultAction == null)
                    {
                        HomeViewModel.RequestResultAction = (RequestResult result) =>
                        {
                            switch (result.Success)
                            {
                            case true:
                                EditInfo.EditInfoWindow.Dispatcher.Invoke(() =>
                                {
                                    EditInfo.EditInfoWindow?.Close();
                                });
                                MessageBox.Show("密码保存成功!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Asterisk);
                                break;

                            case false:
                                MessageBox.Show("输入的旧密码与原密码不一致!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
                                break;

                            default:
                                MessageBox.Show("密码保存失败!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                                break;
                            }
                        };

                        if (!Config.MiniClient.SendDatabaseRequest(new User()
                        {
                            UserName = _userModel.UserName, Password = oldPassword
                        }, "AlterPassword", newPassword))
                        {
                            HomeViewModel.RequestResultAction = null;
                            MessageBox.Show("保存密码时发生错误!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    return;
                }
                MessageBox.Show("密码不符合要求!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            MessageBox.Show("密码不能为空!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Warning);
        }
 public void Trim()
 {
     if (!string.IsNullOrEmpty(CurrentPassword))
     {
         CurrentPassword = CurrentPassword.Trim();
     }
     if (!string.IsNullOrEmpty(NewPassword))
     {
         NewPassword = NewPassword.Trim();
     }
     if (!string.IsNullOrEmpty(ConfirmNewPassword))
     {
         ConfirmNewPassword = ConfirmNewPassword.Trim();
     }
 }
        public async void SetNewPassword()
        {
            var Toast = DependencyService.Get <IMessage>();

            //if (string.IsNullOrEmpty(NewPassword) && string.IsNullOrEmpty(ConfirmNewPassword))
            //{
            //    Toast.LongAlert("All fields are mandatory."); return;
            //}
            if (string.IsNullOrEmpty(NewPassword))
            {
                Toast.LongAlert("Please enter your password."); return;
            }
            if (!Regex.IsMatch(NewPassword, @"^(?=.*[a-z])(?=.*[A-Z])\S{8,15}$", RegexOptions.None) || NewPassword.Trim().Length < 8)
            {
                Toast.LongAlert("Password must be between 8 to 15 characters, including uppercase, lowercase letters."); return;
            }
            if (string.IsNullOrEmpty(ConfirmNewPassword))
            {
                Toast.LongAlert("Please re-enter your password."); return;
            }
            if (NewPassword != ConfirmNewPassword)
            {
                Toast.LongAlert("Hey, confirm password should be same as the new password."); return;
            }
            else
            {
                IsBusy = true;
                UserModel model = new UserModel()
                {
                    EmailId  = Email,
                    Password = NewPassword
                };
                var response = await new ApiData().PostData <UserModel>("user/ResetPassword", model, true);
                if (response != null && response.status == "Success")
                {
                    Toast.LongAlert("Password update successful!");
                    await NavigationService.NavigateAsync("SignInPage");
                }
                else
                {
                    Toast.LongAlert(response.message);
                }

                IsBusy = false;
            }
        }
        public async void ChangePassword()
        {
            var confirm = await Application.Current.MainPage.DisplayAlert(Resx.AppResources.ChangePasswordTitle, Resx.AppResources.ChangePasswordWarning,
                                                                          Resx.AppResources.Yes, Resx.AppResources.Cancel);

            if (confirm)
            {
                var userService = new Services.UserService();
                var result      = await userService.ChangePassword(OldPassword.Trim(), NewPassword.Trim());

                if (result != UsuarioResultEnum.Ok)
                {
                    var toastService = new Services.ToastService();
                    toastService.SendToast(result.GetText());
                }
                else
                {
                    var navigationService = new Services.NavigationService();
                    userService.DoLogout();
                    navigationService.GoToLogin();
                }
            }
        }