0

如何使用 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();

当我执行此代码时,它返回 MySql Data Reader 库而不是数据库中的盐......

提前致谢... :)

4

1 回答 1

0

在这里,我解决了我的问题。这是问题的解决方案。它可能会帮助某人:

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);
        }
于 2017-04-24T00:25:57.523 回答