Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Security.Cryptography;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using MySql.Data.MySqlClient;
- using System.IO;
- namespace WindowsFormsApp5
- {
- public partial class logowanie : Form
- {
- MySqlConnection polaczenie = new MySqlConnection("server=sql.djkelvin.nazwa.pl; user=djkelvin_drukarnia; password=ZAQ!2wsx; database=djkelvin_drukarnia");
- MySqlCommand komenda;
- string zapytanieSQL = "";
- public logowanie()
- {
- InitializeComponent();
- }
- private void haslo_Click(object sender, EventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void wejscie_Click(object sender, EventArgs e)
- {
- try
- {
- if (polaczenie.State == ConnectionState.Closed)
- polaczenie.Open();
- string haslo = "";
- using (MD5 md5 = MD5.Create())
- {
- haslo = GetMD5Hash(md5, haslotb2.Text);
- }
- zapytanieSQL = string.Format("select count(Id) from uzytkownicy where Login = '{0}' and Haslo = '{1}'", logintb1.Text, haslo);
- komenda = new MySqlCommand(zapytanieSQL, polaczenie);
- int wartosc = Convert.ToInt32(komenda.ExecuteScalar());
- if (wartosc == 0)
- MessageBox.Show("Brak takiego użytkownika", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
- else if (wartosc > 0)
- this.Close();
- new strona().Show();
- }
- catch (Exception ex)
- {
- string byk = string.Format("Problem podczas logowania:\n'{0}'");
- MessageBox.Show(byk, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- polaczenie.Close();
- }
- if (string.IsNullOrWhiteSpace(logintb1.Text) || string.IsNullOrWhiteSpace(haslotb2.Text))
- {
- MessageBox.Show("Wszystkie pola muszą być wypełnione", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void nazwa_Click(object sender, EventArgs e)
- {
- }
- private void exit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void exit_Click_1(object sender, EventArgs e)
- {
- this.Close();
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- new Form9().Show();
- this.Hide();
- }
- string GetMD5Hash(MD5 hash, string input)
- {
- byte[] tab = hash.ComputeHash(Encoding.UTF8.GetBytes(input));
- StringBuilder sBuilder = new StringBuilder();
- for (int i = 0; i < tab.Length; i++)
- sBuilder.Append(tab[i].ToString("x2"));
- return sBuilder.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement