Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void flatClose1_Click(object sender, EventArgs e)
- {
- Application.Exit();
- Environment.Exit(4);
- }
- private void flatButton2_Click(object sender, EventArgs e)
- {
- if (!flatTextBox2.Text.Equals("") && !flatTextBox1.Text.Equals("")) ;
- StringBuilder sb = new StringBuilder();
- using (SHA256 hash = SHA256Managed.Create())
- {
- Encoding enc = Encoding.UTF8;
- Byte[] result = hash.ComputeHash(enc.GetBytes(flatTextBox2.Text));
- foreach (Byte b in result)
- {
- sb.Append(b.ToString("x2"));
- }
- }
- string connectionstring = "datasource=127.0.0.1;port=3306;username=root;password=your_password;database=xproject ex;SslMode=none;";
- string query = "INSERT INTO users(ID,Username,Password) VALUES(null, '" + flatTextBox1.Text + "', " + sb.ToString() + "')";
- string query2 = "SELECT * FROM users WHERE username='" + flatTextBox1.Text + "' AND password='" + sb.ToString() + "'";
- MySqlConnection databaseconnection = new MySqlConnection(connectionstring);
- MySqlCommand insertcommand = new MySqlCommand(query, databaseconnection);
- MySqlCommand Checkcommand = new MySqlCommand(query2, databaseconnection);
- insertcommand.CommandTimeout = 60;
- Checkcommand.CommandTimeout = 60;
- MySqlDataReader reader;
- try
- {
- databaseconnection.Open();
- reader = insertcommand.ExecuteReader();
- reader.Close();
- reader = Checkcommand.ExecuteReader();
- if (reader.HasRows)
- {
- MessageBox.Show("You have been registered");
- }
- else
- {
- MessageBox.Show("Sql Code Error");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement