Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Windows.Forms;
- using MetroFramework.Forms;
- using MetroFramework;
- using System.Data.SqlClient;
- using MySql.Data.MySqlClient;
- namespace WRLoader
- {
- public partial class Form1 : MetroForm
- {
- private MySqlConnection conn;
- private string server;
- private string database;
- private string uid;
- private string password;
- public Form1()
- {
- server = "localhost";
- database = "wr";
- uid = "root";
- password = "";
- string connString;
- connString = $"SERVER={server};DATABASE={database};UID={uid};PASSWORD={password};";
- conn = new MySqlConnection(connString);
- InitializeComponent();
- }
- private bool OpenConnection()
- {
- try
- {
- conn.Open();
- return true;
- }
- catch (MySqlException ex)
- {
- switch (ex.Number)
- {
- case 0:
- MessageBox.Show("No Connection");
- break;
- case 1045:
- MessageBox.Show("Server username or password is incorrect!");
- break;
- }
- return false;
- }
- }
- public bool IsLogin(string user, string pass)
- {
- string query = $"SELECT * FROM login WHERE username='{user}' AND password='{pass}';";
- try
- {
- if (OpenConnection())
- {
- MySqlCommand cmd = new MySqlCommand(query, conn);
- MySqlDataReader reader = cmd.ExecuteReader();
- if (reader.Read())
- {
- reader.Close();
- conn.Close();
- return true;
- }
- else
- {
- reader.Close();
- conn.Close();
- return false;
- }
- }
- else
- {
- conn.Close();
- return false;
- }
- }catch (Exception ex)
- {
- conn.Close();
- return false;
- }
- }
- private void metroButton1_Click(object sender, EventArgs e)
- {
- string user = metroTextBox1.Text;
- string pass = MetroTextBox2.Text;
- if(IsLogin(user, pass))
- {
- this.Hide();
- Main mm = new Main();
- mm.Show();
- }
- else
- {
- MessageBox.Show("Please use a valid login", "alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void MetroTextBox2_TextChanged(object sender, EventArgs e)
- {
- MetroTextBox2.UseSystemPasswordChar = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement