I am coding an Application with my friend and I am having some trouble figuring out how to make the 3rd textbox contain a certain word/key to continue in order to make the account
Here is what the form looks like
Then here is the entire code for the database part of where it creates the account.
private void button5_Click(object sender, EventArgs e)
{
if (!textBox1.Text.Equals("") && !textBox2.Text.Equals("") && textBox2.Text.Equals(textBox3.Text))
{
StringBuilder sb = new StringBuilder();
using (SHA256 hash = SHA256Managed.Create())
{
Encoding enc = Encoding.UTF8;
Byte[] result = hash.ComputeHash(enc.GetBytes(textBox2.Text));
foreach (Byte b in result)
{
sb.Append(b.ToString("x2"));
}
}
string connectionString = "datasource=127.0.0.1;port=3306;username=root;password=;database=majorpayne;";
string query = "INSERT INTO staff(USERNAME, PASSWORD) VALUES('" + textBox1.Text + "', '" + sb.ToString() + "')";
string query2 = "SELECT * FROM staff WHERE username='" + textBox1.Text + "' AND password='" + sb.ToString() + "'";
MySqlConnection con = new MySqlConnection(connectionString);
MySqlConnection databaseConnection = new MySqlConnection(connectionString);
MySqlCommand insertCommand = new MySqlCommand(query, databaseConnection);
MySqlCommand checkCommand = new MySqlCommand(query2, databaseConnection);
MySqlDataReader reader;
try
{
databaseConnection.Open();
reader = insertCommand.ExecuteReader();
reader.Close();
reader = checkCommand.ExecuteReader();
if (reader.HasRows)
{
MessageBox.Show("Successfully Created Account.");
{
Login main = new Login();
main.Show();
this.Hide();
}
}
else
{
MessageBox.Show("Database Error (404)");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
}
If anyone can help make a way where the textBox3 equals a specific word thanks in advance.
And for a short explanation, I want the textBox3 to have a "key" in it that checks if the key is the exact key and if the correct key is there, it goes on and creates the account with the user/pass that was entered.