I use PBKDF2 in my application to store user passwords. My Users table has a Salt and Password column which is defined as follows:
On my login page I need to get this salt and password. Since they are byte [] arrays, I store them in my table as varbinary(MAX) . Now I need to get them to compare with the password entered by the user. How would I do this using SqlDataReader ? At the moment I have this:
cn.Open(); SqlCommand Command = new SqlCommand("SELECT Salt, Password FROM Users WHERE Email = @Email", cn); Command.Parameters.Add("@Email", SqlDbType.NVarChar).Value = _Email; SqlDataReader Reader = Command.ExecuteReader(CommandBehavior.CloseConnection); Reader.Read(); if (Reader.HasRows) { // This user exists, check their password with the one entered byte[] _Salt = Reader.GetBytes(0, 0, _Salt, 0, _Salt.Length); } else { // No user with this email exists Feedback.Text = "No user with this email exists, check for typos or register"; }
But I know for sure that this is wrong. Other methods in Reader have only one parameter, which is the index of the column to retrieve.
source share