我有一个与我的 winforms 程序关联的数据库。它存储名称、用户类型、哈希和盐。我已经对注册和写入细节进行了排序,但我不知道如何将盐(从数据库读取时)保存为变量。这是我的代码:
public string getSalt()
{
SqlConnection connection = new SqlConnection(@"server=.\SQLEXPRESS; database=loginsTest;Trusted_Connection=yes");
connection.Open();
string selection = "select DISTINCT Salt from Logins where Name = '"+userNameBox.Text+"'";
SqlCommand command = new SqlCommand(selection, connection);
if (command.ExecuteScalar() != null)
{
connection.Close();
return selection;
}
else
{
connection.Close();
return "Error";
}
}
如您所见,它的返回选择是“从登录名中选择 DISTINCT Salt,其中 Name = '"+userNameBox.Text+"'"。如何将盐保存为要返回的变量?