public bool encodePasswords(string connString) { List <String> list = new List <String>(); using (var con = new SqlConnection(connString)) using (var com = new SqlCommand()) { com.Connection = con; com.CommandText = "SELECT Password from Student"; con.Open(); var dr = com.ExecuteReader(); if (!dr.Read()) { dr.Close(); return(false); } else { while (dr.Read()) { var password = dr["Password"].ToString(); list.Add(password); } dr.Close(); com.Parameters.AddWithValue("Original", ""); com.Parameters.AddWithValue("Salt", ""); com.Parameters.AddWithValue("Encoded", ""); for (int i = 0; i < list.Count; i++) { com.CommandText = "UPDATE Student SET Password=@Encoded, Salt=@Salt WHERE Password=@Original"; string salt = Encode.CreateSalt(); com.Parameters["Original"].Value = list[i]; com.Parameters["Salt"].Value = salt; com.Parameters["Encoded"].Value = Encode.Create(list[i], salt); com.ExecuteNonQuery(); } return(true); } } return(false); }