Generate ASP.Net Membership password hash in pure T-SQL

后端 未结 5 1870
天命终不由人
天命终不由人 2020-12-31 10:32

I\'m attempting to create a pure t-sql representation of the default SHA-1 password hashing in the ASP.Net Membership system. Ideally, what I would get would be this:

<
5条回答
  •  没有蜡笔的小新
    2020-12-31 10:46

    According to this SO post, this is the process they use to encode/hash your password/salt.

    public string EncodePassword(string pass, string salt)
    {
        byte[] bytes = Encoding.Unicode.GetBytes(pass); //HERE
        byte[] src = Encoding.Unicode.GetBytes(salt); //and HERE
        byte[] dst = new byte[src.Length + bytes.Length];
        Buffer.BlockCopy(src, 0, dst, 0, src.Length);
        Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
        HashAlgorithm algorithm = HashAlgorithm.Create("SHA1");
        byte[] inArray = algorithm.ComputeHash(dst); //then they has the bytes not the string...
        return Convert.ToBase64String(inArray);
    }
    

    I could be wrong but it looks like you are missing the step where you get the bytes for the password and salt. Can you try adding that and see if it works?

提交回复
热议问题