アプリケーションを実行すると、最後まで問題なく実行されますが、後で DB を確認すると、データが表示されません。これが私のコードです:
private void button1_Click(object sender, EventArgs e)
{
string saltedcryps = saltpassword(10);
string passWithSalt = (textBox1.Text + saltedcryps);
string hashedResult = hashPassAndSalt(passWithSalt);
if (checkPasswordsMatch() == "B")
{
SqlCeConnection myConnection = new SqlCeConnection("Data Source = pwdb.sdf");
try
{
myConnection.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
SqlCeCommand myCommand = new SqlCeCommand("INSERT INTO PW Values ('Master', '" + saltedcryps + "', '" + hashedResult + "');", myConnection);
myCommand.ExecuteNonQuery();
myConnection.Close();
this.Hide();
}
}
private string checkPasswordsMatch()
{
if (textBox1.Text == "")
{
MessageBox.Show("Passwords cannot be empty");
return "A";
}
else
{
MessageBox.Show(textBox1.Text == textBox2.Text ? "Thanks for registering!" : "Your passwords do not match");
return "B";
}
}
private string saltpassword(int size)
{
RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
byte[] buff = new byte[size];
crypto.GetBytes(buff);
return Convert.ToBase64String(buff);
}
private string hashPassAndSalt(string passWithSalt)
{
HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(passWithSalt);
byte[] bytHash = hashAlg.ComputeHash(bytValue);
string base64 = Convert.ToBase64String(bytHash);
return base64;
}
}
問題があるのは button1_Click です。 myCommand.ExecuteNonQuery(); を実行すると、例外をスローすることはなく、実際に情報を入力せずに続行します...
誰にも手がかりがありますか??