Encoding.ASCII.GetString(o.Username) == textBox1.Text
これは、以前私がこの問題を解決するために与えたコードでした。私は自分のコードにどこに置くべきかわからない。助けてください!!演算子 '=='は、 'byte []'型と 'string'型のオペランドには適用できません。編集済み
これはエラーとセクションです:
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("Please Enter your username.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
textBox1.Focus();
return;
}
try
{
using (DataEntities test = new DataEntities())
{
var query = from o in test.Users
where o.Username == textBox1.Text && o.Password == textBox2.Text
select o;
if(query.SingleOrDefault() != null)
{
MessageBox.Show("You have been successfully logged in.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Add your code process login here
}
else
{
MessageBox.Show("Your username or password is incorrect.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
[投稿した質問](https://stackoverflow.com/questions/47707289/operator-cannot-be-applied-to-operands-of-type-byte-and-string)を再投稿しないでください。 )をクリックして編集します。投稿の[編集](https://stackoverflow.com/posts/47707289/edit)リンクをクリックするだけです。この質問は削除する必要があり、もう1つは問題があれば修正するため編集されています。 –
'o.Password == textBox2.Text' - >あなたは**理想的には塩でユーザーパスワードを**ハッシングする必要があります。単に等価チェックをすることはできません。データベースをハックすると、ユーザーの詳細と平文のパスワードがすべて取得されます。 – john