如何使用带盐的散列密码在服务器上验证客户端?

How to authenticate client at server using a hashed password with salt?

我尝试实现身份验证算法。我现在的基本顺序是 以下:

现在我怀疑这是不是正确的方法。用我想要的盐 防止彩虹 tables 但从服务器请求盐会让 中间攻击的人得到盐,然后破解密码 彩虹 table 使用盐很容易。

是解决这个 https 连接的唯一方法还是有可能 想要节省更多?

  1. 从不存储密码,只存储它的哈希值。
  2. Salt 永远不会离开服务器,生成 salt 并将其作为生成的哈希的一部分。
  3. 使用种子来加强保护。种子可以是从某个预定义日期到用户创建其应用程序登录日期的秒数。

C# 代码示例:

// extends byte[] to create SHA256 hash code with seed and salt of supplied size
public static byte[] GetSHA256HashCode(this byte[] value, byte[] seed, int prefix = 0)
{
    var salt = new byte[prefix];
    RNG.GetBytes(salt);
    return salt.Concat(seed.Concat(salt).Concat(value).ToArray().GetSHA256HashCode()).ToArray();
}

// extends byte[] to compare SHA256 hash code with seed and salt of supplied size to supplied hash code
public static bool IsEqualToSHA256HashCode(this byte[] value, byte[] code, byte[] seed, int prefix = 0)
{
    return seed.Concat(code.Take(prefix)).Concat(value).ToArray().GetSHA256HashCode().SequenceEqual(code.Skip(prefix));
}