public string CalculateHash(string plainTextPassword) { byte[] saltBytes; byte[] hashBytes; PasswordPolicyException error = null; var passwordMeetsPolicy = TryPasswordPolicyCompliance(plainTextPassword, _settings, ref error); if (passwordMeetsPolicy) { saltBytes = GenerateRandomSalt(SaltLength); hashBytes = PasswordToHash(saltBytes, plainTextPassword); } else { throw error; } var salt = HashBytesToHexString(saltBytes); var hash = HashBytesToHexString(hashBytes); var saltAndHash = $"{salt}{Delimiter}{hash}"; return(saltAndHash); }
public static bool TryPasswordPolicyCompliance(string password, PasswordComplexitySettings settings, ref PasswordPolicyException pwdPolicyException) { try { CheckPasswordPolicyCompliance(password, settings); return(true); } catch (PasswordPolicyException ex) { pwdPolicyException = ex; } return(false); }