如何使用 Asp.net 从 MySql 数据库中获取 salt?

How to get salt from MySql database using Asp.net?

如何使用 Asp.Net 从 MySql 数据库中检索盐?

我想使用检索到的盐添加到用户输入的密码中以生成 SHA256 哈希,然后对用户进行身份验证。

这是我试图取盐的方法:

String userNameEntered = UserN_TextBox.Text;
String passwordEntered = Password_TextBox.Text;
String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
connection = new MySqlConnection(connectionString);
connection.Open();
MessageBox.Show("Successfully connected to database");
String queryString = "select salt from xyz.abc_table where salt = @Salt";
command = new MySqlCommand(queryString, connection);
command.Parameters.AddWithValue("@Salt", queryString);
reader = command.ExecuteReader();
Response.Write("Salt retrived is" + reader);
reader.Close();
connection.Close();

当我执行这段代码时,它 returns MySql 数据 Reader 库而不是数据库中的盐....

提前致谢...:)

到这里我的问题已经解决了。这是问题的解决方案。它可能对某人有帮助:

try
        {

            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            connection = new MySqlConnection(connectionString);
            connection.Open();
            MessageBox.Show("Successfully connected to database");
            String queryString = "select salt from xyz.abc_table where email_address = @E_Address";
            command = new MySqlCommand(queryString, connection);
            command.Parameters.AddWithValue("@E_Address", UserN_TextBox.Text);
            reader = command.ExecuteReader();
            if (reader.Read())
            {
                Response.Write("Retrived Salt is " + reader["salt"]);
                reader.Close();
                connection.Close();
            }

        }
        catch (Exception ex)
        {
            MessageBox.Show("Failed due to" +ex);
        }