Exemplo n.º 1
0
        private async Task ChangePassword()
        {
            if (NewPassword.Equals(ConfirmPassword))
            {
                var result = await WebAPI.Instance.ChangePasswordHttpRequest(OldPassword, NewPassword);

                if (result != null)
                {
                    var    JsonResult = JObject.Parse(result);
                    string ResultCode = JsonResult ["error_Code"].ToString();
                    if (ResultCode == "0")
                    {
                        MessagingCenter.Send <ChangePasswordVM> (this, Strings.ChangePassword_SUCCESS);
                    }
                    else
                    {
                        MessagingCenter.Send <ChangePasswordVM> (this, Strings.ChangePassword_FAILURE);
                    }
                }
            }
            else
            {
                GlobalVariables.DisplayMessage = "New Password and Confirm Password must be same";
                MessagingCenter.Send <ChangePasswordVM> (this, Strings.Display_Message);
            }
        }
Exemplo n.º 2
0
 private void EditAccountOk()
 {
     try
     {
         if (CheckFields())
         {
             if (accountService.SetChangesAsync(new AccountServiceReference.Person {
                 Email = Email, Phone = Phone, UserName = UserName
             }, Account.GetInstace().Session).Result)
             {
                 Account.GetInstace().Email    = Email;
                 Account.GetInstace().Phone    = Phone;
                 Account.GetInstace().UserName = UserName;
             }
             if (!OldPassword.Equals(string.Empty) && !NewPassword.Equals(string.Empty))
             {
                 accountService.ChangePasswordAsync(Convert.ToBase64String(Hash.GenerateHash(Encoding.UTF8.GetBytes(OldPassword))), Convert.ToBase64String(Hash.GenerateHash(Encoding.UTF8.GetBytes(NewPassword))), Account.GetInstace().Session);
             }
         }
     }
     catch (Exception e)
     {
         ErrorMessage = e.Message;
     }
 }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!NewPassword.Equals(ConfirmPassword))
            {
                ModelState.AddModelError(string.Empty, "Confirm Password doesn't match Password.");
                return(Page());
            }

            var user = await UserManager.FindByEmailAsync(Email);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToPage("/Account/ResetPasswordConfirmation"));
            }

            var result = await UserManager.ResetPasswordAsync(user, Code, NewPassword);

            if (result.Succeeded)
            {
                return(RedirectToPage("/Account/ResetPasswordConfirmation"));
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!NewPassword.Equals(ConfirmPassword))
            {
                ModelState.AddModelError(string.Empty, "Confirm Password doesn't match Password.");
                return(Page());
            }

            var user = await UserManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{UserManager.GetUserId(User)}'."));
            }

            var changePasswordResult = await UserManager.ChangePasswordAsync(user, OldPassword, NewPassword);

            if (!changePasswordResult.Succeeded)
            {
                foreach (var error in changePasswordResult.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
                return(Page());
            }
            await SignInManager.RefreshSignInAsync(user);

            return(RedirectToPage("/Account/Profile"));
        }
 public void AddValidationErrors(CustomValidationContext context)
 {
     if (!NewPassword.Equals(RepeatNewPassword))
     {
         context.Results.Add(new ValidationResult("两次输入的新密码不一致"));
     }
 }
Exemplo n.º 6
0
        private void CreateUserButton_Click(object sender, EventArgs e)
        {
            string digsign = Guid.NewGuid().ToString();

            if (!NewName.Text.Trim().Equals("") && !NewPassword.Equals("") && !NewUsername.Text.Trim().Equals(""))
            {
                SqlConnection sqlConnection1 = new SqlConnection(connectionString);
                SqlCommand    cmd            = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                //cmd.CommandText = "delete from dbo.BranchSubject where Branch=\'" + BranchModify.Text.Trim() + "\' and Code=\'" + SubjectModify.SelectedItem.ToString() + "\';";

                cmd.CommandText = "insert dbo.Users (Name, UserName, Password, DigitalSignature) values (\'" + NewName.Text.Trim() + "\', \'" + NewUsername.Text.Trim() + "\', \'" + NewPassword.Text + "\', \'" + digsign + "\');";
                cmd.Connection  = sqlConnection1;
                sqlConnection1.Open();

                try
                {
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("User Successfully Created.");
                    NewName.Text     = "";
                    NewPassword.Text = "";
                    NewUsername.Text = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to create user.");
                }

                sqlConnection1.Close();
            }
            else
            {
                MessageBox.Show("Please fill in all the fields.");
            }
        }
Exemplo n.º 7
0
        private void UpdateNewPasswordAwareTextBlock()
        {
            NewPasswordAwareMessage mes = NewPasswordAwareMessage.WhiteSpaceAware;

            if (NewPassword.Contains(" "))
            {
                NewPasswordAwareTextBlockVisibility = Visibility.Visible;
                mes = NewPasswordAwareMessage.WhiteSpaceAware;
            }
            else if (NewPassword.Equals(CurrentUser.Password))
            {
                NewPasswordAwareTextBlockVisibility = Visibility.Visible;
                mes = NewPasswordAwareMessage.SameBefore;
            }
            else if (NewPassword.Length < PharmacyDefinitions.MINIMUM_PASSWORD_LENGHT)
            {
                NewPasswordAwareTextBlockVisibility = Visibility.Visible;
                mes = NewPasswordAwareMessage.NotMeetLenght;
            }
            else if (NewPassword.IndexOfAny(PharmacyDefinitions.SPECIAL_CHARS_OF_PASSWORD) == -1)
            {
                NewPasswordAwareTextBlockVisibility = Visibility.Visible;
                mes = NewPasswordAwareMessage.WrongFormat;
            }
            else
            {
                NewPasswordAwareTextBlockVisibility = Visibility.Collapsed;
            }

            NewPasswordAwareTextBlockContent = mes.GetStringValue();
        }
 protected override void OnConfirmed(CancelEventArgs e)
 {
     if (String.IsNullOrEmpty(EMail))
     {
         e.Cancel     = true;
         ErrorMessage = "Email Address cannot be empty.";
     }
     else if (String.IsNullOrEmpty(NewPassword) ||
              String.IsNullOrEmpty(VerifyPassword))
     {
         e.Cancel     = true;
         ErrorMessage = "Passwords cannot be empty.";
     }
     else if (!NewPassword.Equals(VerifyPassword))
     {
         e.Cancel     = true;
         ErrorMessage = "Passwords must match.";
     }
     else
     {
         var result = provider.RegisterAccount(this.cloud, EMail, NewPassword);
         if (!result.Response)
         {
             ErrorMessage = result.Message;
             e.Cancel     = true;
         }
     }
 }
Exemplo n.º 9
0
        private async Task SavePassword()
        {
            //Check if any field is empty
            if (string.IsNullOrWhiteSpace(OldPassword) || string.IsNullOrWhiteSpace(NewPassword) || string.IsNullOrWhiteSpace(ConfirmedPassword))
            {
                ErrorField = "One or more fields are empty";
            }

            //Check if OldPassword is equals to UserPassword
            else if (!OldPassword.Equals(Application.Current.Properties["Password"]))
            {
                ErrorField = "Old password is not correct";
            }

            //Check if NewPassword and ConfirmedPassword are equals
            else if (!NewPassword.Equals(ConfirmedPassword))
            {
                ErrorField = "Old and new password do not match";
            }

            //If everything is correct
            else if (NewPassword.Equals(ConfirmedPassword))
            {
                //Try to save
                if (await App.loginService.ChangePassword(OldPassword, NewPassword))
                {
                    ErrorField = "Password successfully changed";
                }
                else
                {
                    ErrorField = "An error has occured, please try again";
                }
            }
        }
Exemplo n.º 10
0
        private void SetupCommands()
        {
            ChangePasswordCommand = new Command(async(e) => {
                if (NewPassword.Equals(ConfirmPassword))
                {
                    var bytes = Util.EncryptAes(NewPassword);
                    string encryptedNewPassword = BitConverter.ToString(bytes);

                    //Todo remove once password field is added on the server side
                    //var mobileUserService = new MobileUserService();
                    //AppMobileUser user = new AppMobileUser();
                    //user.password = encryptedNewPassword;
                    //AppMobileUser updatedUser  = await mobileUserService.UpdateMobileUser(user);

                    //update password in local database
                    DatabaseHelper.GetInstance().ChangePassword(NewPassword);
                    await Application.Current.MainPage.DisplayAlert("", AppConstant.SuccessPasswordChange, AppConstant.Done);
                    await navigation.PopAsync();
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("", AppConstant.PasswordUnmatchedError, AppConstant.Done);
                }
            });
        }
Exemplo n.º 11
0
        private bool ValidateData()
        {
            if (string.IsNullOrEmpty(CurrentPassword))
            {
                AlertDialog = "You must enter your Current Password";
                EntryEmpty  = "Red";
                return(false);
            }

            if (string.IsNullOrEmpty(NewPassword) || NewPassword?.Length < 6)
            {
                AlertDialog = "You must enter your New Password";
                EntryEmpty  = "Red";
                return(false);
            }

            if (string.IsNullOrEmpty(ConfirmPassword))
            {
                AlertDialog = "You must enter the Password Confirmation";
                EntryEmpty  = "Red";
                return(false);
            }
            if (!NewPassword.Equals(ConfirmPassword))
            {
                AlertDialog = "The new password and the confirmation does not match";
                EntryEmpty  = "Red";
                return(false);
            }
            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Returns true if UserPasswordChangeSubmit instances are equal
        /// </summary>
        /// <param name="other">Instance of UserPasswordChangeSubmit to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(UserPasswordChangeSubmit other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Uuid == other.Uuid ||
                     Uuid != null &&
                     Uuid.Equals(other.Uuid)
                     ) &&
                 (
                     NewPassword == other.NewPassword ||
                     NewPassword != null &&
                     NewPassword.Equals(other.NewPassword)
                 ) &&
                 (
                     NewPasswordConfirmed == other.NewPasswordConfirmed ||
                     NewPasswordConfirmed != null &&
                     NewPasswordConfirmed.Equals(other.NewPasswordConfirmed)
                 ) &&
                 (
                     OldPassword == other.OldPassword ||
                     OldPassword != null &&
                     OldPassword.Equals(other.OldPassword)
                 ));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Returns true if SessionsModel5 instances are equal
        /// </summary>
        /// <param name="other">Instance of SessionsModel5 to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(SessionsModel5 other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     OldPassword == other.OldPassword ||
                     OldPassword != null &&
                     OldPassword.Equals(other.OldPassword)
                     ) &&
                 (
                     NewPassword == other.NewPassword ||
                     NewPassword != null &&
                     NewPassword.Equals(other.NewPassword)
                 ) &&
                 (
                     Email == other.Email ||
                     Email != null &&
                     Email.Equals(other.Email)
                 ));
        }
Exemplo n.º 14
0
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(UserName))
            {
                MessageBox.Show("Enter user name");
                return;
            }
            if (!string.IsNullOrEmpty(OldPassword) && !string.IsNullOrEmpty(NewPassword))
            {
                if (!NewPassword.Equals(ConfirmPassword))
                {
                    MessageBox.Show("Password not match");
                    return;
                }

                UsersRepository _userRepo = new UsersRepository();
                Users           _user     = _userRepo.FindByQuery(" username = '******' AND Password = '******'").FirstOrDefault();

                if (_user != null)
                {
                    _user.Password = NewPassword;
                    _userRepo.Update(_user);
                }
                else
                {
                    MessageBox.Show("User Not Found");
                }
            }
            else
            {
                MessageBox.Show("Enter Valid Passwords");
                return;
            }
        }
Exemplo n.º 15
0
 private bool EqualsNewPassword()
 {
     if (NewPassword.Equals(PasswordCheck))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 16
0
 private bool ValidateNewPasswordReEnter()
 {
     if (NewPasswordReEnter.Length == 0)
     {
         PasswordError = "Please re-enter the password";
         NewPasswordReEnterErrorFrame = Visibility.Visible;
         return(false);
     }
     if (!NewPassword.Equals(NewPasswordReEnter))
     {
         PasswordError = "Passwords don't match!";
         NewPasswordReEnterErrorFrame = Visibility.Visible;
         return(false);
     }
     return(true);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Tjekker om passwords er ens og ikke er tomme
 /// </summary>
 /// <returns>bool</returns>
 private bool PasswordChecker()
 {
     if (NewPassword != null && NewPasswordCheck != null && CurrentPassword != null)
     {
         if (NewPassword.Equals(NewPasswordCheck) && CurrentPassword.Equals(MC.CurrentUser.Password))
         {
             MC.CurrentUser.Password = NewPassword;
             return(true);
         }
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 18
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrWhiteSpace(Username))
            {
                yield return(new ValidationResult("Username is required", new[] { "Username" }));
            }

            if (string.IsNullOrWhiteSpace(NewPassword))
            {
                yield return(new ValidationResult("New password is required", new[] { "NewPassword" }));
            }
            else if (!NewPassword.Equals(ConfirmPassword, StringComparison.InvariantCulture))
            {
                yield return(new ValidationResult("New password and Confirm password are not identical", new[] { "NewPassword" }));
            }
        }
Exemplo n.º 19
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                throw new VinoArgNullException();
            }

            if (!NewPassword.Equals(ConfirmPassword))
            {
                throw new VinoArgNullException("两次输入的密码不一致!");
            }
            await _userService.ChangePassword(User.GetUserIdOrZero(), CurrentPassword, NewPassword);

            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);

            return(Json(true));
        }
Exemplo n.º 20
0
 private bool CheckFields()
 {
     if (Email.Equals(string.Empty) || Phone.Equals(string.Empty) || UserName.Equals(string.Empty))
     {
         throw new Exception("Please fill out the fields");
     }
     if (FieldValidation.ValidatePhone(Phone))
     {
     }
     if (!OldPassword.Equals(string.Empty) && !NewPassword.Equals(string.Empty))
     {
         if (!FieldValidation.ValidatePassword(NewPassword))
         {
             throw new Exception("Not a valid password");
         }
     }
     return(true);
 }
Exemplo n.º 21
0
        public bool Validate(out ValidationError errors)
        {
            ValidationError error = ValidationError.New();

            if (string.IsNullOrWhiteSpace(OldPassword) && string.IsNullOrWhiteSpace(ResetCode))
            {
                error.AddError(nameof(OldPassword), $"Old Password or Reset Code is required");
                error.AddError(nameof(ResetCode), "Reset Code or Old Password is required");
            }

            if (!Guid.TryParse(UserId, out Guid userGuid))
            {
                error.AddError(nameof(UserId), "UserId is not in correct format");
            }

            if (userGuid == null || userGuid == Guid.Empty)
            {
                error.AddError(nameof(UserId), "UserId is required");
            }

            if (string.IsNullOrWhiteSpace(NewPassword))
            {
                error.AddError(nameof(NewPassword), $"New Password is required");
            }

            if (string.IsNullOrWhiteSpace(NewPassword2))
            {
                error.AddError(nameof(NewPassword2), $"New Password 2 is required");
            }

            if (!NewPassword.Equals(NewPassword2))
            {
                error.AddError(nameof(NewPassword2), $"Passwords must match");
            }

            if (error.HasError)
            {
                errors = error;
                return(false);
            }

            errors = null;
            return(true);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 修改密码
        /// </summary>
        private void OnExecutePasswordChangeCmd()
        {
            if (!NewPassword.Equals(NewPasswordAgain) || string.IsNullOrWhiteSpace(NewPassword) || string.IsNullOrWhiteSpace(NewPasswordAgain))
            {
                MessageBox.Show("您输入的两次新密码不相同,请确认!");
                return;
            }

            var rst = DataRepository.Instance.RePass(UserInfo.LoginName, NewPassword, SecurityCode);

            if (!rst.success)
            {
                MessageBox.Show(rst.message);
            }
            else
            {
                MessageBox.Show("修改密码成功!请使用新的密码重新登录!");
            }
        }
Exemplo n.º 23
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (!string.IsNullOrEmpty(OldPassword))
     {
         if (string.IsNullOrEmpty(NewPassword))
         {
             yield return(new ValidationResult("New password cannot be blank"));
         }
         else if (string.IsNullOrEmpty(ConfirmPassword))
         {
             yield return(new ValidationResult("The the password and confirm password must be the same."));
         }
         else if (NewPassword.Equals(OldPassword))
         {
             yield return(new ValidationResult("The old and new password must be different"));
         }
         else if (!NewPassword.Equals(ConfirmPassword))
         {
             yield return(new ValidationResult("The the password and confirm password must be the same."));
         }
     }
 }
 protected override void OnConfirmed(CancelEventArgs e)
 {
     if (String.IsNullOrEmpty(NewPassword) ||
         String.IsNullOrEmpty(VerifyPassword))
     {
         e.Cancel     = true;
         ErrorMessage = "Passwords cannot be empty.";
     }
     else if (!NewPassword.Equals(VerifyPassword))
     {
         e.Cancel     = true;
         ErrorMessage = "Passwords must match.";
     }
     else
     {
         ProviderResponse <bool> result = provider.ChangePassword(cloud, NewPassword);
         if (!result.Response)
         {
             ErrorMessage = result.Message;
             e.Cancel     = true;
         }
     }
 }
Exemplo n.º 25
0
 private bool CheckFields()
 {
     return(!string.IsNullOrWhiteSpace(OldPassword) && !string.IsNullOrWhiteSpace(NewPassword) &&
            !string.IsNullOrWhiteSpace(RepeatNewPassword) && NewPassword.Length >= 8 &&
            NewPassword.Equals(RepeatNewPassword));
 }
Exemplo n.º 26
0
        async void SavePassword()
        {
            if (string.IsNullOrEmpty(OldPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "Debe ingresar una nueva Contraseña.");

                return;
            }

            if (string.IsNullOrEmpty(NewPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "Debe ingresar una nueva Contraseña.");

                return;
            }

            if (NewPassword.Length < 6)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "La contraseña nueva debe tener al menos 6 caracteres de longitud.");

                return;
            }

            if (string.IsNullOrEmpty(Confirm))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "Debe ingresar una contraseña de confirmación.");

                return;
            }

            if (!NewPassword.Equals(Confirm))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "La contraseña nueva y confirmar, no coincide.");

                return;
            }



            IsRunningPassword = true;
            IsEnabledPassword = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunningPassword = false;
                IsEnabledPassword = true;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }
            else
            {
                var urlAPI = Application.Current.Resources["URLAPI"].ToString();

                var response = await apiService.GetBy <Usuario>(
                    urlAPI,
                    "/api",
                    "/Usuarios",
                    usuario.Correo);


                var user = (Usuario)response.Result;

                if (OldPassword != user.Password)
                {
                    IsRunningPassword = false;
                    IsEnabledPassword = true;
                    await dialogService.ShowMessage(
                        "Error",
                        "Contraseña actual incorrecta");

                    // OldPassword = null;
                    // NewPassword = null;
                    // Confirm = null;
                    return;
                }

                var otherConnection = await apiService.CheckConnection();

                if (!otherConnection.IsSuccess)
                {
                    IsRunningPassword = false;
                    IsEnabledPassword = true;
                    await dialogService.ShowMessage("Error", connection.Message);

                    return;
                }
                else
                {
                    usuario.Password = NewPassword;
                    var Newresponse = await apiService.Put(
                        urlAPI,
                        "/api",
                        "/Usuarios",
                        usuario);

                    if (!Newresponse.IsSuccess)
                    {
                        IsRunningPassword = false;
                        IsEnabledPassword = true;
                        await dialogService.ShowMessage(
                            "Error",
                            Newresponse.Message);

                        return;
                    }

                    var mainViewModel = MainViewModel.GetInstance();
                    mainViewModel.Usuario = (Usuario)response.Result;
                    mainViewModel.Perfil  = new PerfilViewModel(mainViewModel.Usuario);

                    IsRunningPassword = false;
                    IsEnabledPassword = true;

                    await dialogService.ShowMessage(
                        "Alerta",
                        "La contraseña ha sido cambiada.");

                    navigationService.SetMainPage("LoginView");
                }
            }
        }
Exemplo n.º 27
0
        public void Done(object arg)
        {
            if (!_mode.Equals("New") && (CurrentPassword == null || !ComputeHash(CurrentPassword).Equals(App.SettingsHelper.PasswordHash)))
            {
                ShowMessage(AppResources.PasswordIncorrectMessageText, AppResources.PasswordIncorrectMessageCaption, System.Windows.MessageBoxButton.OK);
                return;
            }

            if (!_mode.Equals("Off") && (NewPassword == null || NewPassword.Length < 4))
            {
                ShowMessage(AppResources.PasswordShortMessageText, AppResources.PasswordShortMessageCaption, System.Windows.MessageBoxButton.OK);
                return;
            }

            if (!_mode.Equals("Off") && NewPassword != null && (ConfirmPassword == null || !NewPassword.Equals(ConfirmPassword)))
            {
                ShowMessage(AppResources.PasswordNoMatchMessageText, AppResources.PasswordNoMatchMessageCaption, System.Windows.MessageBoxButton.OK);
                return;
            }

            if (_mode.Equals("Off"))
            {
                App.SettingsHelper.RequirePassword = false;
                App.SettingsHelper.PasswordHash    = null;
                App.SettingsHelper.PasswordLength  = 0;
            }
            else
            {
                App.SettingsHelper.RequirePassword = true;
                App.SettingsHelper.PasswordHash    = ComputeHash(NewPassword);
                App.SettingsHelper.PasswordLength  = NewPassword.Length;
            }

            App.SettingsHelper.SaveSettings();
            App.IsAuthenticated = true;

            if (NavigationService.CanGoBack)
            {
                NavigationService.GoBack();
            }
        }
Exemplo n.º 28
0
        async void Save()
        {
            if (string.IsNullOrEmpty(CurrentPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter the current password.");

                return;
            }

            var mainViewModel = MainViewModel.GetInstance();

            if (!mainViewModel.Token.Password.Equals(CurrentPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The current password is not valid");

                return;
            }

            if (string.IsNullOrEmpty(NewPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a new password.");

                return;
            }

            if (NewPassword.Length < 6)
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The new password must have at least 6 characters length.");

                return;
            }

            if (string.IsNullOrEmpty(ConfirmPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "You must enter a new password confirm.");

                return;
            }

            if (!NewPassword.Equals(ConfirmPassword))
            {
                await dialogService.ShowMessage(
                    "Error",
                    "The new password and confirm, does not match.");

                return;
            }

            IsRunning = true;
            IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage("Error", connection.Message);

                return;
            }

            var changePasswordRequest = new ChangePasswordRequest
            {
                CurrentPassword = CurrentPassword,
                Email           = mainViewModel.Token.UserName,
                NewPassword     = NewPassword,
            };

            //var urlAPI = Application.Current.Resources["URLAPI"].ToString();
            var urlAPI   = "http://productszuluapi.azurewebsites.com";
            var response = await((ApiServiceWithoutConnection)apiService).ChangePassword(
                urlAPI,
                "/api",
                "/Customers/ChangePassword",
                mainViewModel.Token.TokenType,
                mainViewModel.Token.AccessToken,
                changePasswordRequest);

            if (!response.IsSuccess)
            {
                IsRunning = false;
                IsEnabled = true;
                await dialogService.ShowMessage(
                    "Error",
                    response.Message);

                return;
            }

            mainViewModel.Token.Password = NewPassword;
            dataService.Update(mainViewModel.Token);

            await dialogService.ShowMessage(
                "Confirm",
                "The password was changed successfully");

            await navigationService.BackOnMaster();

            IsRunning = false;
            IsEnabled = true;
        }
        public async void UpdateCommandExecute()
        {
            bool updateCredentials = false;
            RestServiceConsumer service;

            SetActivity(true);
            //Conexion
            service = new RestServiceConsumer();
            var response = await service.CheckConnection();

            if (!response.IsSuccesFull)
            {
                SetActivity(false);
                //No hay conexion
                CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                response.Message, iconResource: "error64", textSize: 16);
                return;
            }
            try
            {
                //Chequeo de vacios
                if (!AllDataChecker())
                {
                    //Faltan datos
                    SetActivity(false);
                    CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                    Languages.AllDataNeeded, iconResource: "error64", textSize: 16);
                    return;
                }

                if (!NameChecker(this.Nombres.TrimEnd(' ')) || !NameChecker(this.Apellidos.TrimEnd(' ')))
                {
                    SetActivity(false);
                    //Los nombres o apellidos no han sido bien escritos}
                    if (!NameChecker(this.Nombres.TrimEnd(' ')))
                    {
                        CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                        Languages.WronWGNames, iconResource: "error64", textSize: 16);
                    }
                    else
                    {
                        CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                        Languages.WronWGivenNames, iconResource: "error64", textSize: 16);
                    }
                    return;
                }

                //Chequeo de password correcto
                if (Settings.SuccesfullPassword != this.OldPassword)
                {
                    SetActivity(false);
                    //No coinciden las contraseñas
                    CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                    Languages.PasswordsDontMatch, iconResource: "error64", textSize: 16);
                    return;
                }

                //Se quiere actualizar algo de la seccion de credenciales?
                if (!this.NewPassword.Equals(string.Empty) || !this.RepeatPassword.Equals(string.Empty))
                {
                    //Todos los datos fueron proporcionados?
                    if (NewPassword.Equals(string.Empty) || RepeatPassword.Equals(string.Empty))
                    {
                        SetActivity(false);
                        CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                        Languages.AllDataNeeded, iconResource: "error64", textSize: 16);
                        return;
                    }
                    //Chequeo de repeticion de nueva contraseña
                    if (this.NewPassword != this.RepeatPassword)
                    {
                        SetActivity(false);
                        //No coinciden las contraseñas
                        CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                        Languages.PasswordsShouldMatch, iconResource: "error64", textSize: 16);
                        return;
                    }
                    else
                    {
                        updateCredentials = true;
                    }
                }


                //Creacion del modelo a enviar
                Stream streamedImage = GetImageSourceStream(this.Profile.ProfileImage);
                this.ProfileImageBytes = StreamToByteArray(streamedImage);


                var token = Settings.SerializedToken;

                var posted = new ApiPlainClientProfile()
                {
                    ID              = Settings.ClientUID,
                    PrimerNombre    = this.Nombres.Split(' ')[0],
                    SegundoNombre   = this.Nombres.Split(' ')[1],
                    Apellido        = this.Apellidos.Split(' ')[0],
                    SegundoApellido = this.Apellidos.Split(' ')[1],
                    Email           = this.Profile.Email,
                    PP              = this.ProfileImageBytes,
                    Afiliado        = DateTime.Now
                };

                var posted2 = new ApiClientCredentials()
                {
                    IdClient  = -1,
                    IdPersona = posted.ID,
                    Password  = this.NewPassword,
                    UserName  = "******"
                };

                Response result2 = null;
                var      result  = await service.Put <ApiPlainClientProfile>(Constantes.BASEURL, Constantes.CLIENTPREFIX, Constantes.CLIENTUPDATEPROFILE, posted, token);

                if (updateCredentials)
                {
                    result2 = await service.Put <ApiClientCredentials>(Constantes.BASEURL, Constantes.CLIENTPREFIX, Constantes.CLIENTUPDATECREDENTIALS, posted2, token);
                }

                if (updateCredentials)
                {
                    if (!result.IsSuccesFull || !result2.IsSuccesFull)
                    {
                        SetActivity(false);
                        //Error en la peticion
                        if (!result.IsSuccesFull)
                        {
                            CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                            result.Message, iconResource: "error64", textSize: 16);
                            SetActivity(false);
                            return;
                        }
                        else
                        {
                            CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                            result2.Message, iconResource: "error64", textSize: 16);
                        }
                        SetActivity(false);
                        return;
                    }
                    Settings.SuccesfullPassword = this.NewPassword;
                }
                else
                {
                    if (!result.IsSuccesFull)
                    {
                        CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                        result.Message, iconResource: "error64", textSize: 16);
                        SetActivity(false);
                        return;
                    }
                }

                SetActivity(false);
                CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                Languages.UpdatedProfile, iconResource: "ok96", textSize: 16);
                UpdateLocalProfileInfo(posted);
            }
            catch (Exception ex)
            {
                CustomizedToast(Android.Graphics.Color.White, Android.Graphics.Color.Black,
                                ex.Message, iconResource: "error64", textSize: 16);
                SetActivity(false);
                throw ex;
            }
        }
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (!string.IsNullOrEmpty(NewPassword) && !string.IsNullOrEmpty(NewPasswordConfirm) && !NewPassword.Equals(NewPasswordConfirm))
     {
         yield return(new ValidationResult(
                          "請填入與新密碼同樣的內容", new[] { "NewPasswordConfirm" }));
     }
 }