我有一个与我的winforms程序相关的数据库。它存储名称,usertype,哈希和盐。我排序了注册和写作细节,但我不知道如何将盐(从数据库读取时)作为变量保存。这里是我的代码:从数据库检索盐
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";
}
}
正如你可以看到,它的返回选项,即“+ userNameBox.Text +‘‘’从哪里登录名= SELECT DISTINCT盐’”。我如何将盐保存为要返回的变量?
这是容易受到SQL注入式攻击。它实际上是乞求被黑客攻击。 –
但即时使用盐和哈希?那么我如何返回盐? –
安全问题并不是盐/哈希值(尽管人们也经常犯这个错误)。这是您构建查询的方式。 –