Advertisement
Guest User

Mop 5.4.7 account/ream creator

a guest
Feb 6th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace insert_into_db
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.         private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  21.         {
  22.  
  23.         }
  24.         private void textbox_username_TextChanged(object sender, EventArgs e)
  25.         {
  26.             label_Account_Created.Visible = false;
  27.             label14.Visible = false;
  28.  
  29.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  30.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  31.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  32.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  33.         }
  34.  
  35.         private void button_create_acc_Click(object sender, EventArgs e)
  36.         {
  37.  
  38.             if (textbox_username.Text == "")
  39.             {
  40.                 MessageBox.Show("Username column should not be empty", "Error");
  41.                 return;
  42.             }
  43.             if (textBox_password.Text == "")
  44.             {
  45.                 MessageBox.Show("Password column should not be empty", "Error");
  46.                 return;
  47.             }
  48.  
  49.             MySqlConnection connection = new MySqlConnection("datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text);
  50.             string insertQuery = SQL_textbox.Text;
  51.             connection.Open();
  52.             MySqlCommand command = new MySqlCommand(insertQuery, connection);
  53.  
  54.             // Test
  55.             try
  56.             {
  57.                 label_Account_Created.Visible = true;
  58.                 if (command.ExecuteNonQuery() == 1)
  59.                 {
  60.                     label_Account_Created.Visible = true;
  61.                 }
  62.                 else
  63.                 {
  64.                     //MessageBox.Show("Data Not Inserted");
  65.                     //label2.ForeColor = Color.Red;
  66.                     //label2.Text = "Eroare!";
  67.                     //MessageBox.Show("Unable to connect to any of the specified MySQL hosts.");
  68.                 }
  69.             }
  70.             catch (Exception ex)
  71.             {
  72.                 MessageBox.Show(ex.Message);
  73.             }
  74.             connection.Close();
  75.         }
  76.  
  77.         private void textBox_password_TextChanged(object sender, EventArgs e)
  78.         {
  79.             label_Account_Created.Visible = false;
  80.             label14.Visible = false;
  81.  
  82.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  83.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  84.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  85.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  86.         }
  87.  
  88.         private void label7_Click(object sender, EventArgs e)
  89.         {
  90.  
  91.         }
  92.  
  93.         private void label1_Click(object sender, EventArgs e)
  94.         {
  95.  
  96.         }
  97.  
  98.         private void button1_Click_1(object sender, EventArgs e)
  99.         {
  100.            Properties.Settings.Default.Save();
  101.             try
  102.             {
  103.                 string myConnection = "datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text;
  104.                 MySqlConnection myConn = new MySqlConnection(myConnection);
  105.                 MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
  106.                
  107.                 MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
  108.                 myConn.Open();
  109.                 DataSet ds = new DataSet();
  110.                 label7.Visible = true;
  111.                 label1.Visible = true;
  112.                 label2.Visible = true;
  113.                 textbox_username.Visible = true;
  114.                 textBox_password.Visible = true;
  115.                 button_create_acc.Visible = true;
  116.                 tabControl1.Visible = false;
  117.                 label_MySQL_Connected.Visible = true;
  118.                 label_MySQL_NotConnected.Visible = false;
  119.  
  120.                 label13.Visible = true;
  121.                 textBox_realm_Name.Visible = true;
  122.                 button_Add_realm.Visible = true;
  123.                 comboBox_account_access_level.Visible = true;
  124.                 label11.Visible = true;
  125.                 timer1.Enabled = true;
  126.                 myConn.Close();
  127.             }
  128.             catch (Exception ex)
  129.             {
  130.                 MessageBox.Show(ex.Message);
  131.             }
  132.         }
  133.  
  134.         private void comboBox_account_access_level_SelectedIndexChanged(object sender, EventArgs e)
  135.         {
  136.             label_Account_Created.Visible = false;
  137.             label14.Visible = false;
  138.  
  139.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  140.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  141.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  142.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  143.  
  144.             textBox_account_access_level.Text = comboBox_account_access_level.Text;
  145.  
  146.             if (comboBox_account_access_level.Text == "0 (Player)") textBox_account_access_level.Text = "0";
  147.             else if (comboBox_account_access_level.Text == "1 (GM)") textBox_account_access_level.Text = "1";
  148.             else if (comboBox_account_access_level.Text == "2 (Moderator)") textBox_account_access_level.Text = "2";
  149.             else if (comboBox_account_access_level.Text == "3 (Admin)") textBox_account_access_level.Text = "3";
  150.             else if (comboBox_account_access_level.Text == "4 (Console)") textBox_account_access_level.Text = "4";
  151.  
  152.         }
  153.  
  154.         private void button2_Click(object sender, EventArgs e)
  155.         {
  156.             if (textBox_realm_Name.Text == "")
  157.             {
  158.                 MessageBox.Show("Realm Name should not be empty", "Error");
  159.                 return;
  160.             }
  161.             MySqlConnection connection = new MySqlConnection("datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text);
  162.             string insertQuery = "DELETE FROM " + textBox_authDB.Text + ".realmlist WHERE id=1;" +
  163.                 "INSERT INTO " + textBox_authDB.Text + ".realmlist " +
  164.                 "Values (1, '" + textBox_realm_Name.Text + "', '127.0.0.1', 8085, 0, 0, 1, 0, 0, 18019, 1, 0, 0);";
  165.             connection.Open();
  166.             MySqlCommand command = new MySqlCommand(insertQuery, connection);
  167.  
  168.             try
  169.             {
  170.                 label14.Visible = true;
  171.                 if (command.ExecuteNonQuery() == 1)
  172.                 {
  173.                     label14.Visible = true;
  174.                 }
  175.                 //else
  176.                 //{
  177.                 //    //MessageBox.Show("Data Not Inserted");
  178.                 //    //label2.ForeColor = Color.Red;
  179.                 //    //label2.Text = "Eroare!";
  180.                 //    //MessageBox.Show("Unable to connect to any of the specified MySQL hosts.");
  181.                 //}
  182.             }
  183.             catch (Exception ex)
  184.             {
  185.                 MessageBox.Show(ex.Message);
  186.             }
  187.             connection.Close();
  188.         }
  189.  
  190.         private void textBox_realm_Name_TextChanged(object sender, EventArgs e)
  191.         {
  192.             label14.Visible = false;
  193.             label_Account_Created.Visible = false;
  194.         }
  195.  
  196.         private void label13_Click(object sender, EventArgs e)
  197.         {
  198.  
  199.         }
  200.  
  201.         private void textBox_account_access_level_TextChanged(object sender, EventArgs e)
  202.         {
  203.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  204.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  205.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  206.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  207.         }
  208.  
  209.         private void textBox_authDB_TextChanged(object sender, EventArgs e)
  210.         {
  211.  
  212.         }
  213.  
  214.         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  215.         {
  216.             Properties.Settings.Default.textbox = textBox_mysql_pass.Text;
  217.             Properties.Settings.Default.Save();
  218.         }
  219.  
  220.         private void Form1_Load(object sender, EventArgs e)
  221.         {
  222.             textBox_mysql_pass.Text = Properties.Settings.Default.textbox;
  223.  
  224.         }
  225.  
  226.         private void textBox_mysql_pass_TextChanged(object sender, EventArgs e)
  227.         {
  228.            
  229.         }
  230.  
  231.         private void timer1_Tick(object sender, EventArgs e)
  232.         {
  233.             try
  234.             {
  235.                 string myConnection = "datasource = " + textBox_hostname.Text + "; port = " + textBox_port.Text + "; username = " + textBox_mysql_username.Text + "; password = " + textBox_mysql_pass.Text;
  236.                 MySqlConnection myConn = new MySqlConnection(myConnection);
  237.                 MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
  238.                 //myDataAdapter.SelectCommand = new MySqlCommand("select * from auth.account;");
  239.                 MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
  240.                 myConn.Open();
  241.                 DataSet ds = new DataSet();
  242.                 label_con_lost.Visible = false;
  243.                 label_MySQL_NotConnected.Visible = false;
  244.                 label_MySQL_Connected.Visible = true;
  245.                 myConn.Close();
  246.             }
  247.             catch (Exception ex)
  248.             {
  249.                 //MessageBox.Show(ex.Message);
  250.                 label_con_lost.Visible = true;
  251.                 label_MySQL_NotConnected.Visible = false;
  252.                 label_MySQL_Connected.Visible = false;
  253.             }
  254.         }
  255.     }
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement