/// <summary> /// Verify the given Argon2 hash as being that of the given password. /// </summary> /// <param name="encoded"> /// The Argon2 hash string. This has the actual hash along with other parameters used in the hash. /// </param> /// <param name="password"> /// The password to verify /// </param> /// <returns> /// True on success; false otherwise. /// </returns> public static bool Verify( string encoded, byte[] password) { SecureArray <byte> hash = null; try { var configToVerify = new Argon2Config { Password = password }; if (!configToVerify.DecodeString(encoded, out hash) || hash == null) { return(false); } var hasherToVerify = new Argon2(configToVerify); var hashToVerify = hasherToVerify.Hash(); return(!hash.Buffer.Where((b, i) => b != hashToVerify[i]).Any()); } finally { hash?.Dispose(); } }
/// <summary> /// Verify the given Argon2 hash as being that of the given password. /// </summary> /// <param name="encoded"> /// The Argon2 hash string. This has the actual hash along with other parameters used in the hash. /// </param> /// <param name="configToVerify"> /// The configuration that contains the values used to created <paramref name="encoded"/>. /// </param> /// <returns> /// True on success; false otherwise. /// </returns> public static bool Verify( string encoded, Argon2Config configToVerify) { SecureArray <byte> hash = null; try { if (!configToVerify.DecodeString(encoded, out hash) || hash == null) { return(false); } using (var hasherToVerify = new Argon2(configToVerify)) { using (var hashToVerify = hasherToVerify.Hash()) { return(!hash.Buffer.Where((b, i) => b != hashToVerify[i]).Any()); } } } finally { hash?.Dispose(); } }