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"; } } }
/// <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) )); }
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; } }
/// <summary> /// 验证旧密码和新密码 /// </summary> /// <param name="validationContext"></param> /// <returns></returns> public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (OldPassword.Equals(Password)) { yield return(new ValidationResult( "旧密码不能和新密码一致" , new[] { nameof(Password) } )); } }
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); }
public void changePassword() { Password = password.GetComponent <InputField> ().text; ConfirmPassword = confirmPassword.GetComponent <InputField> ().text; OldPassword = PlayerPrefs.GetString("UserPassword"); userEmail = PlayerPrefs.GetString("UserEmail"); if (OldPassword.Equals(Password) && Password.Equals(ConfirmPassword)) { promptUser.text = "Password cannot be the same as the old one"; } else if (Password.Equals(ConfirmPassword) && !(Password.Equals(userEmail))) { lsd.login.Remove(userEmail); lsd.login.Add(userEmail, Password); promptUser.text = "Password changed successfully"; } else { promptUser.text = "Error"; } }