WCF/REST hash/salt datamember field

2019-08-24 06:59发布

I have a datacontract and in my service I am trying to hash/salt the password datamember:

    public void AddStudent(Student student)
    {
        student.StudentID = (++eCount).ToString();
        byte[] passwordHash = Hash(student.Password, _passwordSalt); //invalid expression? _passwordSalt?
        student.TimeAdded = DateTime.Now;
        students.Add(student);
    }

Can anyone help?

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-24 07:22

Try to replace the _passwordSalt with this function GenerateSalt() from one of my projects:

protected RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();

public byte[] GenerateSalt() {
    byte[] salt = new byte[10];
    random.GetNonZeroBytes(salt);
    return salt;
}

By the way you have to save this generated salt. You need the same salt every time to check the password.

查看更多
登录 后发表回答