public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var errors = new List <ValidationResult>(); var personLoginAccount = HttpRequestStorage.DatabaseEntities.Person.PersonLoginAccount; var isSelfEdit = personLoginAccount.PersonID == PersonID; if (isSelfEdit && !PBKDF2PasswordHash.ValidatePassword(personLoginAccount.PasswordSalt, OldPassword, personLoginAccount.PasswordHash)) { errors.Add(new SitkaValidationResult <ChangePasswordViewModel, string>("Bad password", z => z.OldPassword)); } if (string.IsNullOrEmpty(NewPassword)) { errors.Add(new SitkaValidationResult <ChangePasswordViewModel, string>("Please specify a new password", z => z.NewPassword)); } if (string.IsNullOrEmpty(ConfirmNewPassword)) { errors.Add(new SitkaValidationResult <ChangePasswordViewModel, string>("Please confirm the new password", z => z.ConfirmNewPassword)); } if (NewPassword != ConfirmNewPassword) { errors.Add(new SitkaValidationResult <ChangePasswordViewModel, string>("Passwords must match.", z => z.NewPassword)); } if (!PasswordHelper.VerifyPasswordComplexity(NewPassword)) { errors.Add(new ValidationResult(PasswordHelper.GetPasswordComplexityErrorMessage(NewPassword))); } return(errors); }
private static bool DoPasswordsMatch(PersonLoginAccount personLoginAccount, string passwordPlainText) { string passwordStoredHash = personLoginAccount.PasswordHash; string passwordStoredSalt = personLoginAccount.PasswordSalt; bool matchesPassword = PBKDF2PasswordHash.ValidatePassword(passwordStoredSalt, passwordPlainText, passwordStoredHash); return(matchesPassword); }