1

私の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";
        }
    }

ご覧のとおり、返される選択は、「name = '"+userNameBox.Text+"' のログインから DISTINCT Salt を選択する」です。返す変数としてソルトを保存するにはどうすればよいですか?

4

1 に答える 1