在我的代码中,程序应该检查用户是否有一个帐户,并查看用户是否有一个7人的次级组。如果这些都是真的,我想然后将计算机的HWID插入同一帐户下的members_hwid字段。我不知道如何在1命令中完成所有这些,因此我编写了另一个函数来将hwid插入帐户名称中。问题是它创建了一个不同的帐户,然后把假帐户的hwid。。我怎样才能解决这个问题,它把hwid下正确的帐户?下面是我当前运行的代码:
private void button1_Click(object sender, EventArgs e)
{
string server = "207.244.70.217";
string database = "nextgene_NGH";
string uid = "EXAMPLEUID";
string password = "EXAMPLEPASSWORD";
string ssl = "None";
string connectionString = $"SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};SSL Mode={ssl};";
using var connection = new MySqlConnection(connectionString);
connection.Open();
using var command = new MySqlCommand("SELECT members_pass_hash FROM core_members WHERE name = @name AND mgroup_others = 7;", connection);
command.Parameters.AddWithValue("@name", maskedTextBox1.Text);
var hashedPassword = (string)command.ExecuteScalar();
try
{
if (!(hashedPassword is null && !BCrypt.Net.BCrypt.Verify(maskedTextBox2.Text, hashedPassword)))
{
if (checkBox1.Checked)
{
Properties.Settings.Default.username = maskedTextBox1.Text;
Properties.Settings.Default.password = maskedTextBox2.Text;
Properties.Settings.Default.Save();
}
var vip = new vipform();
vip.Show();
HM();
}
}
catch (Exception ex)
{
MessageBox.Show("ISSUE IS: " + ex);
//MessageBox.Show("Either Login information is Incorrect or You are not VIP.");
}
CHECKHWID();
}
当它完成执行时,它会调用CHECKHWID函数,即:
public void CHECKHWID()
{
try
{
string server = "207.244.70.217";
string database = "nextgene_NGH";
string uid = "EXAMPLEUID";
string password = "EXAMPLEPASSWORD";
string ssl = "None";
string connectionString = $"SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};SSL Mode={ssl};";
using var connection = new MySqlConnection(connectionString);
connection.Open();
using var command = new MySqlCommand("INSERT INTO core_members(name, member_hwid) VALUES (@name, @hwid)", connection);
command.Parameters.AddWithValue("@hwid", HWIDNumber);
command.Parameters.AddWithValue("@name", maskedTextBox1.Text);
var hashedPassword = (string)command.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show("ISSUE IS: " + ex);
}
}
最后,当我在执行CHECKHWID后检查数据库时,我看到它使用HWID添加了另一个名为XXX的用户,但它没有将HWID添加到button1_click的原始用户或名称中。我做错了什么?
1条答案
按热度按时间lymnna711#
在SQL查询的WHERE子句中,尝试使用用户名而不是hwid。
提示:SET member_hwid = @hwid WHERE name = @name