を検証します。ここに私のコードは次のとおりです。bcryptのは、私がDBにハッシュされたパスワードを保存しようとしているパスワード
string passwords = textBox2.Text;
string salt = BCrypt.Net.BCrypt.GenerateSalt(12);
string hashPwd = BCrypt.Net.BCrypt.HashPassword(passwords, salt);
try
{
SQLiteCommand command = new SQLiteCommand();
connection.Open();
command.Connection = connection;
command.CommandText = ((@"INSERT INTO acc (UserName, Pass) VALUES ('" + textBox1.Text + "','" + hashPwd+ "');"));
command.ExecuteNonQuery();
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error:" + ex.ToString());
return;
}
ログイン/検証コード:
try
{
SQLiteDataAdapter sqlad = new SQLiteDataAdapter("SELECT COUNT(*) From acc WHERE Username = '" + textBox1.Text + "' AND Pass = '" + textBox2.Text + "' ", connection);
DataTable dt = new DataTable();
sqlad.Fill(dt);`
string userid = dt.Rows[0]["UserName"].ToString();
string password = dt.Rows[0]["Pass"].ToString();
bool flag = BCrypt.Net.BCrypt.Verify(textBox2.Text, password);
if (userid == textBox1.Text && flag == true)
{
Form2 frm = new Form2();
frm.Show();
}
else
{
MessageBox.Show("Invalid UserId or password");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
私はパスワードを確認できない、私はエラーを取得しています、あなたは私を助けてくださいだろうか?もう一つ質問ですが、塩分もデータベースに保存すべきですか?
でしょうか?あなたのデータベースのパスワードはハッシュされており、おそらく 'textBox2.Text'にプレーンテキストが含まれているので、何も見つかりません。'UserName'と' Pass'カラムではなく、カウントを返すので、結果セットには含まれません。最後に、SQLインジェクションを読んで読んでみたいかもしれません。 – steve16351
ユーザーが入力したパスワードと、データベースにハッシュされたパスワードを比較するにはどうすればよいですか? –
[この記事](https://crackstation.net/hashing-security.htm)であり、特に、[このセクション](https://crackstation.net/hashing-security.htm#properhashing)を見て@LuisVito 。関連する手順がここにリストされています。記事全体を読むことを検討してください。それはいいです:-) – khlr